def dataReceived(self, data):
        """
        Called whenever data is received.

        @type data: L{bytes}
        @param data: Part or all of a SOCKSv4 packet.
        """
        if self.otherConn:
            self.otherConn.write(data)
            return
        self.buf = self.buf + data
        completeBuffer = self.buf
        if b"\000" in self.buf[8:]:
            head, self.buf = self.buf[:8], self.buf[8:]
            version, code, port = struct.unpack("!BBH", head[:4])
            user, self.buf = self.buf.split(b"\000", 1)
            if head[4:7] == b"\000\000\000" and head[7:8] != b"\000":
                # An IP address of the form 0.0.0.X, where X is non-zero,
                # signifies that this is a SOCKSv4a packet.
                # If the complete packet hasn't been received, restore the
                # buffer and wait for it.
                if b"\000" not in self.buf:
                    self.buf = completeBuffer
                    return
                server, self.buf = self.buf.split(b"\000", 1)
                d = self.reactor.resolve(server)
                d.addCallback(self._dataReceived2, user,
                              version, code, port)
                d.addErrback(lambda result, self = self: self.makeReply(91))
                return
            else:
                server = socket.inet_ntoa(head[4:8])

            self._dataReceived2(server, user, version, code, port)

        Called whenever data is received.

        @type data: L{bytes}
        @param data: Part or all of a SOCKSv4 packet.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/socks.py