title: Connect to Socket server from Actionscript 3 AIR application
body: <p>I read through the method to connect to a socket server : <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_5.html" rel="nofollow">http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_5.html</a></p>
  
  <p>I wrote an AIR application to connect to the java server code, but the client cannot connect. What is missing in the code?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                         xmlns:s="library://ns.adobe.com/flex/spark" 
                         xmlns:mx="library://ns.adobe.com/flex/mx" backgroundColor="#D5F8C3"&gt;
  
      &lt;fx:Script&gt;
          &lt;![CDATA[
  
              import flash.net.XMLSocket;
  
  
  
              var socket:XMLSocket;
  
              public function b1_clickHandler(event:MouseEvent):void
              {
  
                  var socket:XMLSocket;
                  socket.connect("127.0.0.1",8080);
                  socket.send("Hello");
                  //socket.addEventListener(DataEvent.DATA, onData);
  
              }
  
  
  
  
          ]]&gt;
      &lt;/fx:Script&gt;
  
      &lt;fx:Declarations&gt;
          &lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt;
  
  
      &lt;/fx:Declarations&gt;
      &lt;s:Button id="b1" x="285" y="162" label="Send Text" width="201" height="105" click="b1_clickHandler(event)"/&gt;
  &lt;/s:WindowedApplication&gt;
  </code></pre>