Connecting to a Socket Server : Socket « Network « Flash / Flex / ActionScript






Connecting to a Socket Server

 
package {
  import flash.display.Sprite;
  import flash.events.*;
  import flash.net.Socket;

  public class Main extends Sprite {
  
    private var socket:Socket;
  
    public function Main(  ) {
      socket = new Socket(  );
      
      socket.addEventListener( Event.CONNECT, onConnect );
      
      socket.connect( "localhost", 2900 );
    }
    
    private function onConnect( event:Event ):void {
      trace( "The socket is now connected..." );  
    }
    
  }
}

        








Related examples in the same category

1.Receiving Data
2.Handling a Built-in Exception
3.Sending Data
4.Handling Asynchronous Errors: IOErrorEvent
5.Close the Socket in Finally branch