summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-10-05 14:56:17 +0200
committerAleš Smodiš <aless@guru.si>2015-10-05 14:56:17 +0200
commit0818b6655e8fd5ce14febd47470ac0445e3665f1 (patch)
tree801f161ea326bc3120b81d0187c4ac2275043fbf /server
parent361f8245079b625560449324faf111ed6fcf3b1b (diff)
Bugfix: correctly handle python-nodejs transport using bytes.
Diffstat (limited to 'server')
-rw-r--r--server/socket.py11
1 files changed, 5 insertions, 6 deletions
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()