diff options
author | andreas128 <Andreas> | 2017-04-08 16:13:16 +0100 |
---|---|---|
committer | andreas128 <Andreas> | 2017-04-08 16:13:16 +0100 |
commit | 44e44c36309d5ffc557d2a0d70d42b10edcf2120 (patch) | |
tree | 7524c3de2dde31b72e96ae2e24bda8766aa3c3b8 | |
parent | 0104c7642f4ec57e045b315d2fad88c4ebcda22e (diff) | |
download | ODR-StaticPrecorrection-44e44c36309d5ffc557d2a0d70d42b10edcf2120.tar.gz ODR-StaticPrecorrection-44e44c36309d5ffc557d2a0d70d42b10edcf2120.tar.bz2 ODR-StaticPrecorrection-44e44c36309d5ffc557d2a0d70d42b10edcf2120.zip |
Fix receive more bytes then one object
-rw-r--r-- | src/tcp_sync.py | 14 |
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() |