Use XMLSocket to retrieve data : XMLSocket « Network « Flash / Flex / ActionScript






Use XMLSocket to retrieve data

 

package{
  import flash.display.Sprite;
  import flash.net.*;
  import flash.events.*;
  public class Main extends Sprite{
            var socket:XMLSocket = new XMLSocket();
    public function Main(){


        socket.addEventListener(Event.CONNECT, connected);
        socket.addEventListener(DataEvent.DATA, dataReceived);

        socket.connect("localhost", 8989);

    }
            private function connected(event:Event):void
        {
            socket.send("hi");
        }
        private function dataReceived(dataEvent:DataEvent):void
        {
            trace(dataEvent.data);
            var xml:XML = new XML(dataEvent.data);
        }
  }
}

        








Related examples in the same category

1.Listen to the connect event
2.Use XML socket Connect event and Data event