flash socket 发送至服务器

时间:2022-04-04 20:11:36

刚学flash 和 socket,捣腾了好久才写出来的,后来说是要用udp做。。哎白弄。。先保存下吧

附上一边大神博客:http://blog.csdn.net/carmazhao/article/details/7164335

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

 var socket:Socket;
SocketExample();
 function SocketExample(   ) {
   socket = new Socket(   );
   
   // Listen for when data is received from the socket server
   socket.addEventListener( ProgressEvent.SOCKET_DATA, onSocketData );
   // Connect to the server
   socket.connect( "192.168.6.17", 2900 );
}


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


   while ( socket.bytesAvailable ) 

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