log.debug("Binding to: " + bindAddress.getAddress().getHostAddress() + ":" + bindPort);
    public Socket bind(InetSocketAddress isa) throws IOException {        InetAddress addr = isa.getAddress();        byte[] hostbytes = addr.getAddress();        byte[] requestPacket = new byte[300];        requestPacket[0] = PROTOCOL_VERSION; // means socks4 (field VN)        requestPacket[1] = BIND; // means bind (field CD)        requestPacket[2] = (byte) (getPrimaryConnectionPort() >> 8); // (field                                                                        // DSTPORT)        requestPacket[3] = (byte) (getPrimaryConnectionPort() & 0x00ff); // (field                                                                            // DSTPORT)        // adding the host adress bytes to the packet (field DSTIP)        System.arraycopy(hostbytes, 0, requestPacket, 4, 4);        // adding user id to packet (field USERID)        System.arraycopy(getUser().getBytes(), 0, requestPacket, 8, getUser()                .getBytes().length);        // terminate the packet        requestPacket[9 + getUser().getBytes().length] = 0;        byte[] response = new byte[8];        // connect the socket        OutputStream out = null;        InputStream in = null;        try {            connectToProxy();            out = socket.getOutputStream();            in = socket.getInputStream();            out.write(requestPacket, 0, 9 + getUser().getBytes().length);            in.read(response, 0, 8);        } catch (IOException ioe) {            throw new ProxyConnectionException(-2, "SOCK4 - IOException: "                    + ioe.getMessage());        }        if (response[0] != 0 && response[0] != 4)            throw new ProxyConnectionException(-3,                    "SOCKS4 wrong protocol version reply");        ProxyConnectionException pce = null;        switch (response[1]) {        case REQUEST_OK:            break; // bind successfull        case REQUEST_REJECTED_OR_FAILED:            pce = new ProxyConnectionException(REQUEST_REJECTED_OR_FAILED,                    "SOCKS4 request rejected or failed");            break;        case IDENTD_CONNECT_FAILED:            pce = new ProxyConnectionException(                    IDENTD_CONNECT_FAILED,                    "SOCKS4 request rejected becasue SOCKS server cannot connect to identd on the client");            break;        case DIFFERENT_UIDS_GIVEN:            pce = new ProxyConnectionException(                    DIFFERENT_UIDS_GIVEN,                    "SOCKS4 request rejected because the client program and identd report different user-ids.");            break;        default:            pce = new ProxyConnectionException(-1,                    "SOCKS4 unknown proxy response");            break;        }        if (pce != null) {            try {                out.close();                in.close();                this.socket.close();            } catch (IOException ioe) {            }            throw pce;        }        int aPort = response[2];        int bPort = response[3];        aPort = (aPort < 0 ? (aPort + 256) : aPort);        bPort = (bPort < 0 ? (bPort + 256) : bPort);        int bindPort = (aPort << 8) + (bPort);        byte[] bindAddr = { response[4], response[5], response[6], response[7] };        bindAddress = new InetSocketAddress(InetAddress.getByAddress(bindAddr), bindPort);        log.debug("Binding to: " + bindAddress.getAddress().getHostAddress() + ":"                + bindPort);        return this.socket;    }