summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
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()