Receiving Data : Socket « Network « Flash / Flex / ActionScript






Receiving Data

 
Socket read methods for various datatypes

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

  public class SocketExample extends Sprite {
  
    private var socket:Socket;
  
    public function SocketExample(  ) {
      socket = new Socket(  );
      
      socket.addEventListener( ProgressEvent.SOCKET_DATA, onSocketData );

      socket.connect( "localhost", 2900 );
    }

    private function onSocketData( event:ProgressEvent ):void {
      trace( "Socket received " + socket.bytesAvailable + " byte(s) of data:" );

      while ( socket.bytesAvailable ) {
        var data:int = socket.readByte(  );
        trace( data );
      }
    }
  }
}

        








Related examples in the same category

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