fix: correctly receive all chunks in recorder

This commit is contained in:
2025-10-24 22:31:58 +02:00
parent 97f9765705
commit 8d35f76b56
2 changed files with 17 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ class RecorderClient(QObject):
socket.AF_INET, socket.SOCK_STREAM)
self.timer: Optional[QTimer] = None
self.connected: bool = False
self.buffer: bytes = b""
@pyqtSlot()
def start(self):
@@ -40,27 +41,27 @@ class RecorderClient(QObject):
print("Connected to server")
def poll_socket(self):
buffer: bytes = b""
if not self.connected:
return
try:
chunk: bytes = self.socket.recv(self.DATA_CHUNK_SIZE)
if not chunk:
return
buffer += chunk
while True:
if len(buffer) < 4:
break
msg_len: int = struct.unpack(">I", buffer[:4])[0]
msg_end: int = 4 + msg_len
if len(buffer) < msg_end:
break
chunk: bytes = self.socket.recv(self.DATA_CHUNK_SIZE)
if not chunk:
return
self.buffer += chunk
message: bytes = buffer[4:msg_end]
buffer = buffer[msg_end:]
self.on_message(message)
while True:
if len(self.buffer) < 4:
break
msg_len: int = struct.unpack(">I", self.buffer[:4])[0]
msg_end: int = 4 + msg_len
if len(self.buffer) < msg_end:
break
message: bytes = self.buffer[4:msg_end]
self.buffer = self.buffer[msg_end:]
self.on_message(message)
except BlockingIOError:
pass
except Exception as e:

View File

@@ -63,7 +63,7 @@ class Snapshot:
(nbr_raycasts,), data = iter_unpack(">B", data)
raycast_distances, data = iter_unpack(f">{nbr_raycasts}f", data)
(h, w), data = iter_unpack(">ii", data)
(h, w), data = iter_unpack(">II", data)
if h * w > 0:
image = np.frombuffer(data, np.uint8).reshape(h, w, 3)