aboutsummaryrefslogtreecommitdiffstats
path: root/src/tcp_sync.py
diff options
context:
space:
mode:
authorandreas128 <Andreas>2017-04-08 16:13:16 +0100
committerandreas128 <Andreas>2017-04-08 16:13:16 +0100
commit44e44c36309d5ffc557d2a0d70d42b10edcf2120 (patch)
tree7524c3de2dde31b72e96ae2e24bda8766aa3c3b8 /src/tcp_sync.py
parent0104c7642f4ec57e045b315d2fad88c4ebcda22e (diff)
downloadODR-StaticPrecorrection-44e44c36309d5ffc557d2a0d70d42b10edcf2120.tar.gz
ODR-StaticPrecorrection-44e44c36309d5ffc557d2a0d70d42b10edcf2120.tar.bz2
ODR-StaticPrecorrection-44e44c36309d5ffc557d2a0d70d42b10edcf2120.zip
Fix receive more bytes then one object
Diffstat (limited to 'src/tcp_sync.py')
-rw-r--r--src/tcp_sync.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/tcp_sync.py b/src/tcp_sync.py
index 4a5a5b8..79183a2 100644
--- a/src/tcp_sync.py
+++ b/src/tcp_sync.py
@@ -45,23 +45,17 @@ class _TcpSyncClient(threading.Thread):
#Read messages
sock.settimeout(None)
+ s = ""
while self.q_quit.empty():
try:
- s = ""
#concatenate to one package
while self.q_quit.empty():
s += sock.recv(self.packet_size)
- if (len(s)) == self.packet_size:
+ if (len(s)) >= self.packet_size:
break
- if (len(s)) > self.packet_size:
- print("received wrong size of length " + str(len(s)) + " instead of " + str(self.packet_size))
- time.sleep(0.01)
- return -1
-
- res_tuple = struct.unpack(
- self.packet_type,
- s)
+ res_tuple = struct.unpack( self.packet_type, s[:self.packet_size])
+ s = s[self.packet_size:]
self.queue.put(res_tuple)
except socket.timeout:
self.stop()