AS3 SOCKET的简单使用
//真SOCKET类使用
import flash.events.ProgressEvent; var socket:Socket=new Socket(); socket.connect("127.0.0.1",9999); socket.addEventListener("connect",connect) function connect(e:Event){ socket.addEventListener(ProgressEvent.SOCKET_DATA,getData); sendmsg.addEventListener("click",sendmsgs) } function getData(e:ProgressEvent){ //while(socket.bytesAvailable){ getOutText.text=socket.readByte().toString(); getOutText.appendText(socket.readUTFBytes(socket.bytesAvailable)); //} } function sendmsgs(e:MouseEvent){ socket.writeByte(sendInputText.text.length); socket.writeUTFBytes(sendInputText.text); sendInputText.text=""; socket.flush(); //必要的 } /*有特殊用途的话 使用readBytes方法
public function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
从套接字读取 参数
|