Flash
  Home arrow Flash arrow Page 3 - XML Sockets in Flash
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

XML Sockets in Flash
By: Richard Lyman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 25
    2002-04-02

    Table of Contents:
  • XML Sockets in Flash
  • Methods and Properties
  • Common Utilizations
  • Possibilities
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

    More Flash Articles
    More By Richard Lyman


       · Is there a closing bracket that's misplacing in the 2nd implementation...
     

    FLASH ARTICLES

    - 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
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications
    - ActionScript in Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT