Home arrow Flash arrow Page 3 - Communication and Security with the Flash Communication Server
FLASH

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
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

Communication and Security with the Flash Communication Server - The Communication Classes
(Page 3 of 4 )

Remote Methods

In a typical application, an individual client may need to ask the server to perform some action on its behalf. For example, it may need to ask the server for the length of a recorded stream before playing it. The server may also have to ask the client to do something. For example, the server may need to have the client use a unique string provided by the server to name the streams the client will publish. Remote method calls are a way that the client and server can invoke methods on each other.

An application instance can invoke a method on a client using the Client.call( ) method. A client can invoke a method on an application instance using the
NetConnection.call( ) method. For example, a server-side script can invoke a method on an individual client in order to let the client know its unique ID number:

  client.call("setID", null, id);

If a client method named setID( ) is invoked using Client.call( ) from the server, the method must be defined on the client’s NetConnection object or nothing will happen. For example, the client-side script might look like this:

  nc = new NetConnection();
  nc.setID = function (id) {
    myID = id;
  };

Conversely, the client can call a method on the server using a NetConnection object:

  nc.call("getStreamLength", streamInfoResponder, streamName);

For a result to be returned by the remote method, the second parameter passed to NetConnection.call( ) must be a object with an onResult( ) method.

FlashCom also supports mechanisms to send a remote method request to multiple clients at the same time. Clients connected to the same shared object or playing the same stream can all receive a remote method call at the same time. For example, a popular way to update a text chat area is to use the send( ) method of a shared object to send a text message to every client:

  chat_so.send("showMessage", "Welcome to the chat.");

In this case, a showMessage( ) method must be defined on the shared object or nothing will happen:

  chat_so.showMessage = function (msg) {
   
chatTextArea.text += msg + '\n';
   
chatTextArea.vPosition = chatTextArea.maxVPosition;
  };

Chapter 9 describes calling and defining remote methods in detail.

Communicating with Application Servers, Databases, and Directory Servers

Flash and the Flash Communication Server often must work with other existing applications and resources. For example, users may have to log in against an existing directory service or database before being allowed to chat or view streams. Database systems can be used to store large amounts of information that FlashCom cannot easily manage, such as millions of records that represent the location of video messages in a video email system. Each record might contain the email text and the location of the recorded video message within a FlashCom application.

Both the Flash Player and FlashCom can interact with web application servers and, through them, database and directory servers. The Flash client can call any server-side script available on a web server, send and receive XML data, access web services, and use the Flash Remoting gateway to more efficiently access application servers. In contrast, the Flash Communication Server (as of the latest version, 1.5.2) supports only Flash Remoting to connect to other servers. It cannot directly consume web services, send or receive XML, or call a CGI script, which often complicates designing applications that need to access a database or other service already available via a web server. However, Flash Remoting is a powerful and efficient technology that can be used with J2EE, ColdFusion, and .NET servers to provide access to databases or other services. Macromedia sells the Flash Remoting gateway separately for J2EE and .NET servers and bundles it with ColdFusion. There are also open source implementations of Flash Remoting for Perl, PHP, and Java. See Chapter 11 for more details on Remoting, and see http://opensource.org for information on open source code.

Flash Remoting is a request/response technology that allows scripts in the Flash client or FlashCom to call remote methods on an application server. It uses HTTP to send and receive data in the AMF. Those remote methods can retrieve information from a database, directory server, or web server and return the information to FlashCom. From a developer’s point of view, Flash Remoting is easy to work with because complex ActionScript data is serialized and deserialized automatically. Flash Remoting can be used with or without FlashCom. The point is that Flash Remoting is flexible enough that it allows FlashCom to communicate effectively despite FlashCom’s lack of direct support for XML or server-side script access.

Figure 1-5 illustrates some of the communication options for Flash and FlashCom. A Flash client can access a web application directly, as can FlashCom.

In some cases, clients may connect to both an application server and FlashCom. In other cases, FlashCom may connect to the application server and provide information from or to its clients. When many clients need access to the same data, FlashCom should be used as an intermediary between application servers. Application performance will be improved by reducing the number of queries from each Flash


Figure 1-5.  Both the Flash client and FlashCom can access application servers

movie. When each movie needs to look up information unique to it, a direct connection to an application server is usually a better approach.


blog comments powered by Disqus
FLASH ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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