From 0818b6655e8fd5ce14febd47470ac0445e3665f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Mon, 5 Oct 2015 14:56:17 +0200 Subject: Bugfix: correctly handle python-nodejs transport using bytes. --- server/socket.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'server') diff --git a/server/socket.py b/server/socket.py index 60f0704..121c6a4 100644 --- a/server/socket.py +++ b/server/socket.py @@ -125,21 +125,20 @@ class JsonClientSocket(SocketHandler): self.destroy() else: # packet decode loop - data = data.decode('utf-8') print("received: {}".format(data)) offset = 0 N = len(data) while (offset < N): if self.receiving_header: - i = data.find(':', offset) + i = data.find(b':', offset) if i < 0: self.buffer.append(data[offset:]) break if len(self.buffer) == 0: - self.body_length = int(data[offset:i]) + self.body_length = int(data[offset:i].decode('utf-8')) else: self.buffer.append(data[offset:i]) - self.body_length = int(''.join(self.buffer)) + self.body_length = int(b''.join(self.buffer)) self.buffer.clear() offset = i + 1 self.receiving_header = False @@ -153,12 +152,12 @@ class JsonClientSocket(SocketHandler): s = data[offset:offset+self.body_length - self.received_length] # TODO: is this correct? offset += len(s) self.buffer.append(s) - s = ''.join(self.buffer) + s = b''.join(self.buffer) self.buffer.clear() self.received_length = 0 self.receiving_header = True try: - processIncomingPacket(self, s) + processIncomingPacket(self, s.decode('utf-8')) except Exception as e: # any exception that propagates to here means a possible protocol error, we have to disconnect traceback.print_exc() -- cgit v1.2.1