AS3 AIR / FlashBuilder How to release socket on exit?
When I exit from the debugger and relaunch I often get the message:
Error: Error #2002: Operation attempted on invalid socket.
at flash.net::ServerSocket/internalBind()
at flash.net::ServerSocket/bind()
I usually have to wait a while before I can relaunch the application without the error.
How can I avoid this?
private function openConnection():void
{
_serverSocket = new ServerSocket();
_serverSocket.addEventListener(ServerSocketConnectEvent.CONNECT, onConnect)
开发者_JS百科 _serverSocket.bind(888);
_serverSocket.listen();
}
private function onConnect(e:ServerSocketConnectEvent):void
{
trace("Client is connected");
_clientSocket = e.socket;
_clientSocket.addEventListener(ProgressEvent.SOCKET_DATA, onData);
_clientSocket.addEventListener(Event.CLOSE, onConnectionClosed);
}
I don't think you can avoid it. I it just takes awhile for the OS to free the socket after AIR lets go of it. As a workaround, you could catch the error and use a timer to retry binding the socket every few seconds.
And AIR apps never need policy files (unless the code opening the socket was loaded from outside the application).
精彩评论