這裏是插座在AS3中是如何工作的:
首先創建套接字,並添加監聽器:
_socket = new Socket();
// or if secure
_socket = new TLSSocket();
_socket.addEventListener(Event.CONNECT, onConnect);
_socket.addEventListener(ProgressEvent.SOCKET_DATA, onData);
// also add listeners for errors, close etc
_socket.connect(myURL, myPORT);
private function onConnect(event:Event):void{
//connection is live now so do whatever like send something
var request:String = "create a request here";
_socket.writeUTFBytes(request);
_socket.flush();
}
private function onData(event:ProgressEvent):void{
//this gets called EVERY time new data comes over the socket
// the socket will stay connected until you close it (or an error makes it drop)
// here is how you read what came over the socket
while(_socket.bytesAvailable){
theData = _socket.readUTFBytes(_socket.bytesAvailable);
}
// now do something with the data
}
希望幫助你讓你的插座設置
或者之後'socket.connect'如果一切正常,我們得到'socked.connected ==內同樣的功能範圍TRUE'? – myWallJSON
應該沒有時間。最終只能有一個(便宜的漢蘭達插頭)。它應該是監聽連接...然後做東西。雖然很適合inline .. ie如果你在一個onData事件,你正在聽更多的套接字信息..但連接不適用 –