code: private void doAccept() throws IOException{
        Socket s;
        long startTime = System.currentTimeMillis();
  
        while(true){
           s = ss.accept();
           if(s.getInetAddress().equals(msg.ip)){
              //got the connection from the right host
              //Close listenning socket.
              ss.close();
              break;
           }else if(ss instanceof SocksServerSocket){
              //We can't accept more then one connection
              s.close();
              ss.close();
              throw new SocksException(Proxy.SOCKS_FAILURE);
           }else{
              if(acceptTimeout!=0){ //If timeout is not infinit
                 int newTimeout = acceptTimeout-(int)(System.currentTimeMillis()-
                                                             startTime);
                 if(newTimeout <= 0) throw new InterruptedIOException(
                                  "In doAccept()");
                 ss.setSoTimeout(newTimeout);
              }
              s.close(); //Drop all connections from other hosts
           }
        }
  
        //Accepted connection
        remote_sock = s;
        remote_in = s.getInputStream();
        remote_out = s.getOutputStream();
  
        //Set timeout
        remote_sock.setSoTimeout(iddleTimeout);
  
        log("Accepted from "+s.getInetAddress()+":"+s.getPort());
  
        ProxyMessage response;
  
        if(msg.version == 5)
           response = new Socks5Message(Proxy.SOCKS_SUCCESS, s.getInetAddress(),
                                                             s.getPort());
        else
           response = new Socks4Message(Socks4Message.REPLY_OK,
                                        s.getInetAddress(), s.getPort());
        response.write(out);
     }
docs: ////////////////