private void startServers(int proxyPort, int destPort) {
    try {
      _proxyServer = new ServerSocket();
      _proxyServer.bind(new InetSocketAddress(proxyPort));
      _destinationServer = new ServerSocket();
      _destinationServer.bind(new InetSocketAddress(destPort));
    } catch (IOException iox) {
      ErrorService.error(iox);
    }

    Thread proxyThread =
        new ManagedThread() {
          public void managedRun() {
            proxyLoop();
          }
        };
    proxyThread.setDaemon(true);
    proxyThread.start();

    Thread destThread =
        new ManagedThread() {
          public void managedRun() {
            destLoop();
          }
        };
    destThread.setDaemon(true);
    destThread.start();
  }
 private void proxyLoop() {
   try {
     while (true) {
       Socket incomingProxy = null;
       incomingProxy = _proxyServer.accept();
       if (!_proxyOn) fail("LimeWire connected to proxy server instead of directly");
       InputStream is = incomingProxy.getInputStream();
       OutputStream os = incomingProxy.getOutputStream();
       if (_proxyVersion == ProxyTest.SOCKS4) checkSOCKS4(is, os);
       else if (_proxyVersion == ProxyTest.SOCKS5) checkSOCKS5(is, os);
       else if (_proxyVersion == ProxyTest.HTTP) checkHTTP(is, os);
       else assertTrue("test not set up correctly, incorrect proxy version", _isHTTPRequest);
       int a = 0;
       if (_isHTTPRequest) {
         consumeHttpHeaders(is);
         writeHTTPBack(os);
         try {
           Thread.sleep(1000);
         } catch (InterruptedException x) {
         }
       } else {
         // os.write('x');
         while (a != -1) a = is.read();
       }
       if (!incomingProxy.isClosed()) incomingProxy.close();
     }
   } catch (IOException iox) {
     ErrorService.error(iox);
   }
 }
 private void destLoop() {
   try {
     while (true) {
       Socket incomingDest = null;
       incomingDest = _destinationServer.accept();
       if (_proxyOn) fail("Limewire connected to desination instead of proxy");
       if (_isHTTPRequest) {
         writeHTTPBack(incomingDest.getOutputStream());
         try {
           Thread.sleep(1000);
         } catch (InterruptedException e) {
         }
       }
       if (!incomingDest.isClosed()) incomingDest.close();
     }
   } catch (IOException iox) {
     ErrorService.error(iox);
   }
 }