def _dataReceived2(self, server, user, version, code, port):
        """
        The second half of the SOCKS connection setup. For a SOCKSv4 packet this
        is after the server address has been extracted from the header. For a
        SOCKSv4a packet this is after the host name has been resolved.

        @type server: C{str}
        @param server: The IP address of the destination, represented as a
            dotted quad.

        @type user: C{str}
        @param user: The username associated with the connection.

        @type version: C{int}
        @param version: The SOCKS protocol version number.

        @type code: C{int}
        @param code: The comand code. 1 means establish a TCP/IP stream
            connection, and 2 means establish a TCP/IP port binding.

        @type port: C{int}
        @param port: The port number associated with the connection.
        """
        assert version == 4, "Bad version code: %s" % version
        if not self.authorize(code, server, port, user):
            self.makeReply(91)
            return
        if code == 1: # CONNECT
            d = self.connectClass(server, port, SOCKSv4Outgoing, self)
            d.addErrback(lambda result, self = self: self.makeReply(91))
        elif code == 2: # BIND
            d = self.listenClass(0, SOCKSv4IncomingFactory, self, server)
            d.addCallback(lambda (h, p),
                          self = self: self.makeReply(90, 0, p, h))
        else:
            raise RuntimeError, "Bad Connect Code: %s" % code
        assert self.buf == "", "hmm, still stuff in buffer... %s" % repr(
            self.buf)
dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/protocols/socks.py/SOCKSv4._dataReceived2/original