public Socket connect(String host, int port)
            throws ProxyConnectionException {
        setPrimaryConnectionPort(port);

        InetSocketAddress isa = null;

        try {
            isa = new InetSocketAddress(InetAddress.getByName(host), port);
        } catch (IOException ioe) {
            throw new ProxyConnectionException(-2, "SOCK5 - IOException: "
                    + ioe.getMessage());
        }

        InetAddress addr = isa.getAddress();
        byte[] hostbytes = addr.getAddress();
        byte[] requestPacket = new byte[300];
        byte[] response = new byte[2];
        byte methodCount = 2;

        requestPacket[0] = PROTOCOL_VERSION; // means socks5 (field VN)
        requestPacket[1] = methodCount; // methods count (field NMETHODS)
        requestPacket[2] = NO_AUTH; // X'00' NO AUTHENTICATION REQUIRED
        // requestPacket[3] = GSSAPI; // X'01' GSSAPI
        if (getUser() != null && getPass() != null)
            requestPacket[3] = USER_PASS; // X'02' USERNAME/PASSWORD

        try {
            connectToProxy();

            this.socket.getOutputStream().write(requestPacket, 0,
                    methodCount + 2);
            this.socket.getInputStream().read(response, 0, 2);
        } catch (IOException ioe) {
            throw new ProxyConnectionException(-2, "SOCK5 - IOException: "
                    + ioe.getMessage());
        }

        // negotiation for connect method completed
        log.debug("Using method: " + response[1]);

        if (response[1] == 0) { // NO AUTHENTICATION REQUIRED
            return request(hostbytes);
            // }else if (response[1] == 1) { // GSSAPI

        } else if (response[1] == 2) { // USERNAME/PASSWORD
            if (authUserPass(hostbytes))
                return request(hostbytes);
        }

        return null;
    }