Cooperation/Connection.py

changeset 6483
1c0bfbf78353
parent 6048
82ad8ec9548c
child 6484
8bed668f2a85
diff -r 15b0a1583cdd -r 1c0bfbf78353 Cooperation/Connection.py
--- a/Cooperation/Connection.py	Tue Aug 28 18:23:42 2018 +0200
+++ b/Cooperation/Connection.py	Wed Aug 29 19:05:55 2018 +0200
@@ -26,6 +26,7 @@
 PongTimeout = 60 * 1000
 PingInterval = 5 * 1000
 SeparatorToken = '|||'
+SeparatorToken_b = b'|||'
 
 
 class Connection(QTcpSocket):
@@ -293,7 +294,7 @@
         
         while self.bytesAvailable() and self.__buffer.size() < maxSize:
             self.__buffer.append(self.read(1))
-            if self.__buffer.endsWith(SeparatorToken):
+            if self.__buffer.endsWith(SeparatorToken_b):
                 break
         
         return self.__buffer.size() - numBytesBeforeRead
@@ -306,10 +307,10 @@
         """
         if self.bytesAvailable() <= 0 or \
            self.__readDataIntoBuffer() <= 0 or \
-           not self.__buffer.endsWith(SeparatorToken):
+           not self.__buffer.endsWith(SeparatorToken_b):
             return 0
         
-        self.__buffer.chop(len(SeparatorToken))
+        self.__buffer.chop(len(SeparatorToken_b))
         number = self.__buffer.toInt()[0]
         self.__buffer.clear()
         return number
@@ -329,19 +330,20 @@
             return False
         
         self.__buffer.chop(len(SeparatorToken))
-        if self.__buffer == Connection.ProtocolPing:
+        protocolHeader = str(self.__buffer, encoding="utf-8")
+        if protocolHeader == Connection.ProtocolPing:
             self.__currentDataType = Connection.Ping
-        elif self.__buffer == Connection.ProtocolPong:
+        elif protocolHeader == Connection.ProtocolPong:
             self.__currentDataType = Connection.Pong
-        elif self.__buffer == Connection.ProtocolMessage:
+        elif protocolHeader == Connection.ProtocolMessage:
             self.__currentDataType = Connection.PlainText
-        elif self.__buffer == Connection.ProtocolGreeting:
+        elif protocolHeader == Connection.ProtocolGreeting:
             self.__currentDataType = Connection.Greeting
-        elif self.__buffer == Connection.ProtocolGetParticipants:
+        elif protocolHeader == Connection.ProtocolGetParticipants:
             self.__currentDataType = Connection.GetParticipants
-        elif self.__buffer == Connection.ProtocolParticipants:
+        elif protocolHeader == Connection.ProtocolParticipants:
             self.__currentDataType = Connection.Participants
-        elif self.__buffer == Connection.ProtocolEditor:
+        elif protocolHeader == Connection.ProtocolEditor:
             self.__currentDataType = Connection.Editor
         else:
             self.__currentDataType = Connection.Undefined

eric ide

mercurial