'Called whenever data is received.
@type data: L{bytes}
@param data: Part or all of a SOCKSv4 packet.'

def dataReceived(self, data):

    if self.otherConn:
        self.otherConn.write(data)
        return
    self.buf = (self.buf + data)
    completeBuffer = self.buf
    if ('\x00' 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('\x00', 1)
        if ((head[4:7] == '\x00\x00\x00') and (head[7:8] != '\x00')):
            if ('\x00' not in self.buf):
                self.buf = completeBuffer
                return
            (server, self.buf) = self.buf.split('\x00', 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)
