Flash Component: The Lobby

By Bobby on Thu, 1 Jan 2009 08:19:38 +0000

: communication server, lobby, rtmp, flash, component,

The Lobby is an essential part of multiuser applications, such as chat rooms and multiplayer games.
The demo below uses the Bloo Lobby component which handles all the client-server interaction.
The Lobby component encapsulates all the client/server details exposing a simple API:

• onError
• onNewUser
• onNewMessage
• onNewTable
• onMyNewTable

• onDebugInfo
• onInit
• connect
• disconnect
• send

• createTable
• joinTable
• leaveTable
• isConnected
• isConnecting

Making a lobby then is just a matter of putting together the interface, and we won't be tied to any given interface implementation.

Demo





Implementation


The Flash Communication Server makes the creation of multi-user applications straightforward.
There are two sides to each such app. An .as (actionscript) script file placed at the server and which regulates server operation and the client .swf flash client file.


The flash client connects to the Flash Communication Server with the RTMP protocol (TCP Port 1935). At each end point of this client/server connection data comes in as typical Actionscript objects, so the actual protocol implementation is seamless and transparent. At the server we use FCS's server API methods and events, such as onConnect(client, name) and onDisconnect(client) to maintain a list of connected clients.


Whenever a client connects we add that client to the Client data structure and notify every other client of the newcomer's arrival. For best performance try to broadcast only differential updates to the Client list rather than the whole list.
We can use the FCS's Server API methods, such as send() and call() to broadcast and call methods on all and a single client respectively. The newly connected client will need to be Initialized with data such as the Message History and list of connected clients.


Once you have this in place it's easy to expand our application to support "Turns" for example, such as player turns in a chess game. Finally we wrap all this functionality inside a reusable Flash component file (.swc) and a server actionscript file (.as) to avoid repeated work in the future.
Creative Commons License The Flash Component: The Lobby article by Bobby Soares, unless otherwise expressly stated, is licensed under a Attribution-Noncommercial-Share Alike 3.0 United States License.

No comments have been added.


Comment moderation is on, so your comments may not be visible immediately after posting.




(see all) web service, tile engine, google docs, flash, window, penn, pixel, python, game, compiler, server, tlslite, token, reference, rtmp, vmware, p vs np, Google Docs, poweredge, javascript, component, vbulletin, proxy, networking, vmware esxi, GData, forum, plugin, gwt, outlook, scales, puzzle, GWT, java, attach, shining force, subsets, appengine, permutations, pong, authentication, roland, screenshot, np-complete, gdata, neural net, php, latex, audio, AppEngine