Home arrow Flash arrow Page 3 - XML Sockets in Flash
FLASH

XML Sockets in Flash


The purpose of this tutorial is to familiarize readers with the XMLSocket object in Flash, it's methods and properties. Teach the reader the more common methods of using the XMLSocket object, and then open the reader up to the possibilities allowed by the XMLSocket Object.

Author Info:
By: Richard Lyman
Rating: 4 stars4 stars4 stars4 stars4 stars / 30
April 02, 2002
TABLE OF CONTENTS:
  1. · XML Sockets in Flash
  2. · Methods and Properties
  3. · Common Utilizations
  4. · Possibilities
  5. · Summary

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
XML Sockets in Flash - Common Utilizations
(Page 3 of 5 )

Having outlined the methods and event handlers common to the XMLSocket object, let’s discuss how they all work together. Here is some sample code for a connection from Flash to a server with no functionality for sending, receiving, or parsing.

myXML = new XMLSocket; myXML.onConnect = handleConnect; myXML.connect("http://www.yourServer.com", 12345); function handleConnect(connectionStatus){ connectionStatus ? trace("Connected.") : trace("Connection failed."); }
As you can see, there really isn't that much to initiating a socket connection to your server.

So that you can test your Flash code, here is a very condensed socket server written in Perl. This server has no special functionality built in. It simply echoes anything it receives from any client to all clients connected. Notice that the only real change needed from a standard basic socket server is the setting of the null character as the EOL indicator (in Perl: $/="\0";).

use IO::Socket; use IO::Select; $SIG{PIPE}='IGNORE'; $m=new IO::Socket::INET(Listen=>1,LocalPort=>2229); $O=new IO::Select($m); $/="\0"; while(@S=$O->can_read){ foreach(@S){ if($_==$m){ $C=$m->accept;$O->add($C); }else{ my $R=sysread($_, $i, 2048); if($R==0){ $T=syswrite($_, '

', 2048); if($T==undef){ $O->remove($_); } }else{ foreach $C($O->handles){ $T=syswrite($C, $i,2048); } } } } }


As was mentioned in the previous section, any language can handle Flash's sockets, as long as it can open ports, and recognize the null character as an EOL character. Socket apps have been written in Perl, PHP, Java, C++, and I'm sure in many other languages.

Since there really isn't any need to explain the above ActionScript code, we will provide an example that uses most of the functionality the object has to offer.

myXML = new XMLSocket; myXML.onConnect = handleConnect; myXML.onXML = handleXML; myXML.onClose = handleDisconnect; myXML.connect("http://www.yourServer.com", 12345); function handleConnect(connectionStatus){ connectionStatus ? trace("Connected.") : trace("Connection failed."); } function handleXML(xmlObject){ trace("Object recieved:: "+xmlObject); } function sendXML(textToSend){ myXML.send(new XML('"+textToSend+"")); } function handleDisconnect(){ trace("Connection lost."); } function closeConnection(){ trace("Closing connection to server."); myXML.close(); }
That pretty much covers the basic implementation of the methods, and event handlers. But that's only the starting point. Where you take it from here will depend on the solution you're working to implement.
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

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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