Home arrow Flash arrow Communication and Security with the Flash Communication Server

Communication and Security with the Flash Communication Server

In this article you will learn about using the Flash Communication Server with streaming audio, video, and ActionScript data; how to share data in real time; and much more. It is excerpted from chapter one of the book Programming Flash Communication Server, written by Brian Lesser, Giacomo Guilizzoni, Robert Reinhardt, Joey Lott, and Justin Watkins (Copyright © 2005 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media; ISBN: 0596005040).

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 9
December 14, 2006
  1. · Communication and Security with the Flash Communication Server
  2. · Sharing Data in Real Time
  3. · The Communication Classes
  4. · Firewalls and Security

print this article

Communication and Security with the Flash Communication Server
(Page 1 of 4 )

Streaming Audio, Video, and ActionScript Data

Once you establish a connection using a NetConnection object in the client, you can use it to send or receive a stream containing audio and/or video. Suppose you know that a recorded Flash video file named Ryerson_High_Speed.flv is available in the instanceís public directory. You can attach the video stream to a video object, here named videoArea, using Video.attachVideo( ) and play it using NetStream.play( ). The NetStream object,in_ns, is created by passing the NetConnection object,nc, from the preceding example to the NetStream( ) constructor function:

  in_ns = new NetStream(nc);

In this case, the video appears in a video object that was placed on the Stage during authoring and given the instance namevideoArea; the audio within the video stream is heard automatically. Note that the .flv extension is not included in the stream URI passed into the play( ) method.

Publishing a stream in a Flash movie is also easy. Here, we create a new NetStream object,out_ns, and attach the audio and video streams from the userís microphone and camera before publishing the stream using NetStream.publish( ):

  out_ns = new NetStream(nc);
  out_ns.publish(userName);  // Name the stream after the user's name.

The Camera class can get a video stream from a web camera or other video source, and the Microphone class can get an audio stream from a microphone or other source.

You can create multiple streams (NetStream objects) for a single NetConnection,as shown in Figure 1-3. Each stream can publish or play a stream to or from the server, but data within a stream travels in only one direction. If each user must publish a single stream, it is easiest to name the stream after his unique username or unique ID number.

Figure 1-3.  A client publishing a stream and receiving two streams over one NetConnection

On the server, the Stream class can be used to create playlists of streams and even to play and publish streams across multiple servers. A playlist defines a sequence of streams to be played one after the other. The server buffers them so they play seamlessly without interruption; when one stream ends, another begins. Chapter 5 covers the NetStream and Stream classes in depth.

Camera, Microphone, and Video

The Camera and Microphone classes, covered in depth in Chapter 6, provide access to video and audio sources (typically cameras and microphones) on the client system. Multiple cameras and microphones can be accessed by the same Flash movie. Only one video and audio stream can be published or played within a single NetStream; however, there can be multiple NetStreams within a single NetConnection, as shown in Figure1-4. The Flash Player is responsible for encoding all audio and video data. Video encoding from each video source is currently limited to constant bit rate encoding at a single resolution. The Camera and Microphone classes can be used to control the amount of audio and video data being sent to the server and can be dynamically adjusted to match the bandwidth limitations of the clients connected to an application. No real-time hardware encoding options are currently available, though that may have changed by the time you read this. Some video cards can present different resolution video streams from the same input as separate video sources so that multiple NetStream objects carrying different resolution video from the same source can be published simultaneously. Otherwise, the only way to provide different streams matched to the bandwidth of each client is to use multiple video sources.

Figure 1-4.  Attaching audio and video sources to a published stream and attaching a playing stream to an embedded Video object to view incoming video

The Camera class provides a convenient way to change the resolution, frame rate, and quality settings for each video source. The Microphone class allows setting the sampling rate, gain, and silence level, among others. A Video object is used to display video within a Flash movie and can be dynamically resized and moved as video is played. See Chapter 6 for working examples.

blog comments powered by Disqus

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials