AS3 AIR / FlashBuilder 如何在退出时释放套接字?

发布于 2024-12-02 22:48:24 字数 826 浏览 1 评论 0原文

当我退出调试器并重新启动时,我经常收到以下消息:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为你鎻心 2024-12-09 22:48:24

我认为你无法避免它。在 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文