|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
Flash Pushing Data Out to the Flash Client with XMLSockets
An essential for games, presentations, and RIAs
By: Matthew David
Nov. 17, 2003 12:00 AM
In the real world there has to be a constant conversation between the client and the server application. I am going to use e-mail as an example. If you have a traditional POP3 e-mail client (one you get through your ISP or Web hosting company) you have to actively connect to it and check if you have e-mail. You can do this by either hitting the “send and receive” button or setting your e-mail recheck setting to an arbitrary time. A more efficient model would have your email client only check and download email when it's available. Enterprise e-mail systems, such as Microsoft Exchange, leverage both the e-mail client on your desktop and the e-mail server. When email arrives at the server a message is sent to the e-mail client that a new message has been delivered. The server, in this case, pushed data out to the client. Other examples can include realtime data transfer for information such as stock numbers, sales figures, and supply chain management. These areas require a tool that can push data out to a client.
Using XMLSocket
Connections You can dig through the specifications of HTML and you will not find support for XMLSockets. But XMLSocket connection has been a standard feature within Flash since version 5, with only one security feature to worry about (see sidebar). Through ActionScript you can connect to an XMLSocket server, send and receive XML-formatted data, and close connections to the server.
XMLSocket Server Although XMLSocket technology is relatively new, there are a number of notable XMLSocket servers on the market.
You can find an even more comprehensive list of XMLSocket servers on the XML/XMLSocket server list over at the Flash Wiki (http://chattyfig.figleaf. com/flashcoderswiki/index.php?XML%2F XMLSocket%20Servers).
XMLSocket Class in Flash mySocket = new XMLSocket(); Once you have declared you are using an XMLSocket you can connect, send, and close the XMLSocket class. Table I shows methods and their descriptions. There are also event handlers you can use to push and pull data to and from an XMLSocket server. These include:
Creating a Pong Game with
an XMLSocket Server You can download the complete Flash source code to run this game from www.sys-con.com/mx/sourcec.cfm. You will need an XMLSocket server to run the program. The source code is Shovemedia's Pong but you can use any XMLSocket server, such as Unity. I won't go through the mechanics of the game in detail - there are about 500 lines of code. What I want to direct your attention to is the connection to the XMLSocket server and how it is used to create XML data to pass the players' moves back and forth to each other over the Internet. Download the files for the Pong Game. You will want to open pongGame.as. Go to line 287. You will see the the code shown in Code 1. Essentially, you have two functions. The first connects to a server through an open port. The second function prints to the Flash Player whether a connection has been successfully made.
Summary Reader Feedback: Page 1 of 1
Your Feedback
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||