AS3 AIR / FlashBuilder 如何在退出时释放套接字?
当我退出调试器并重新启动时,我经常收到以下消息:
Error: Error #2002: Operation attempted on invalid socket.
at flash.net::ServerSocket/internalBind()
at flash.net::ServerSocket/bind()
我通常必须等待一段时间才能重新启动应用程序而不会出现错误。
我怎样才能避免这种情况?
private function openConnection():void
{
_serverSocket = new ServerSocket();
_serverSocket.addEventListener(ServerSocketConnectEvent.CONNECT, onConnect)
_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);
}
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)
_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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你无法避免它。在 AIR 释放套接字后,操作系统只需要一段时间即可释放套接字。作为解决方法,您可以捕获错误并使用计时器每隔几秒重试绑定套接字。
而且 AIR 应用程序永远不需要策略文件(除非打开套接字的代码是从应用程序外部加载的)。
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).