示例#1
0
    def handle_tcp(self, remote):
        sock = self.request
        sock_list = [sock, remote]
        while 1:
            read_list, _, _ = select(sock_list, [], [])
            if remote in read_list:
                data = remote.recv(8192)
                if not data:
                    break
                enc = cipher.encrypt(data)
                length = len(enc)
                logging.debug('send data to client: {}'.format(length))
                sock.send(u16_to_bytes(length))
                if (sock.send(enc) <= 0):
                    break
            if sock in read_list:
                data = safe_recv(sock, 2)
                if data is None:
                    break
                length = bytes_to_int(data)
                logging.debug('fetching data from client: {}'.format(length))

                data = safe_recv(sock, length)
                if data is None:
                    break
                dec = cipher.decrypt(data)
                logging.debug('send data to server: {}'.format(len(dec)))
                if (remote.send(dec) <= 0):
                    logging.debug('send to server error')
                    break
示例#2
0
    def handle_tcp(self, remote):
        sock = self.request
        sock_list = [sock, remote]
        while True:
            read_list, _, _ = select(sock_list, [], [])
            if remote in read_list:
                data = safe_recv(remote, 2)
                if data is None:
                    break
                length = bytes_to_int(data)
                logging.debug('receiving data from remote: {}'.format(length))
                data = safe_recv(remote, length)
                if not data:
                    break
                dec = cipher.decrypt(data)
                if (sock.send(dec) <= 0):
                    break

            if sock in read_list:
                data = sock.recv(8192)
                if not data:
                    break
                enc = cipher.encrypt(data)
                length = len(enc)
                remote.send(u16_to_bytes(length))
                logging.debug('send data to server: {}'.format(length))
                if (remote.send(enc) <= 0):
                    break
示例#3
0
    def handle_tcp(self, remote):
        sock = self.request
        sock_list = [sock, remote]
        while 1:
            read_list, _, _ = select(sock_list, [], [])
            if remote in read_list:
                data = remote.recv(8192)
                if not data:
                    break
                enc = cipher.encrypt(data)
                length = len(enc)
                logging.debug('send data to client: {}'.format(length))
                sock.send(u16_to_bytes(length))
                if (sock.send(enc) <= 0):
                    break
            if sock in read_list:
                data = safe_recv(sock, 2)
                if data is None:
                    break
                length = bytes_to_int(data)
                logging.debug('fetching data from client: {}'.format(length))

                data = safe_recv(sock, length)
                if data is None:
                    break
                dec = cipher.decrypt(data)
                logging.debug('send data to server: {}'.format(len(dec)))
                if (remote.send(dec) <= 0):
                    logging.debug('send to server error')
                    break