This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
149
Chapter 5
CHAPTER 5
Managing Streams
Streams are a way to organize and manage the flow of data over a network connec-
tion. Audio, video, and ActionScript data can all be carried within a stream. Data
within each stream flows in only one direction, but streams can carry more than one
type of data, and multiple streams can be created within a single network connec-
tion. In many applications, a stream will carry audio and video from a Flash movie to
the FlashCom Server while other streams will carry audio and video from the server
to the movie. Within a Flash movie the NetStream class is used to create and man-
age streams, while on the server the Stream class is used.
Audio and video data is transferred over a network connection by attaching it to a
stream. In FlashCom 1.5.2, a stream can contain only one audio and one video chan-
nel. A movie that creates a stream within a network connection and uses the stream
to send data is publishing data, while a movie that creates a stream to receive data is a
subscriber. A movie must create separate streams within a connection in order to
both publish and subscribe at the same time. Streams can also carry more traditional
data such as strings, numbers, and objects and are FlashCom’s primary method for
storing very large quantities of any kind of data on the server. FlashCom streams can
be recorded and saved to disk by FlashCom in Flash Video format (FLV) files.
The client-side NetStream class can be used to publish or subscribe to a stream. The
Stream class is used on the server to manage or republish streams that are being pub-
lished by a remote movie or that have already been stored as FLV or MP3 files on a
server.
Flash movies must use both a NetConnection and a NetStream object to publish a
stream to a specific application instance. Within the instance, the stream is associ-
ated with a unique relative URI that identifies the stream, which other movies can
use to subscribe. In this way, the application instance acts like a hub that provides a
stream namespace. A stream is published to it so that it can be subscribed to by any
movie connected to the instance. Figure 5-1 shows two Flash movies connected to an
instance of the courseChat application named
algebra101. Each movie has created
two separate NetStream objects named
out_ns and in_ns. Each movie is publishing a

Get Programming Flash Communication Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.