title: AS3 AIR / FlashBuilder How to release socket on exit?
body: <p>When I exit from the debugger and relaunch I often get the message:</p>
  
  <pre><code>Error: Error #2002: Operation attempted on invalid socket.
      at flash.net::ServerSocket/internalBind()
      at flash.net::ServerSocket/bind()
  </code></pre>
  
  <p>I usually have to wait a while before I can relaunch the application without the error.</p>
  
  <p>How can I avoid this?</p>
  
  <pre><code>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);
      }
  </code></pre>