Add debug logging to socket send and receive operations to trace message flow

parent 2fbe9570
......@@ -69,7 +69,9 @@ class SocketCommunicator:
'msg_id': message.msg_id,
'data': message.data
}).encode('utf-8')
self.sock.sendall(data + b'\n')
full_data = data + b'\n'
print(f"DEBUG: SocketCommunicator sending: {full_data}")
self.sock.sendall(full_data)
def receive_message(self) -> Optional[Message]:
"""Receive a message."""
......@@ -150,11 +152,15 @@ class SocketServer:
try:
while self.running:
data = client_sock.recv(4096)
print(f"DEBUG: SocketServer received raw data: {data}")
if not data:
break
messages = data.decode('utf-8').split('\n')
decoded = data.decode('utf-8')
print(f"DEBUG: SocketServer decoded data: {repr(decoded)}")
messages = decoded.split('\n')
for msg_str in messages:
if msg_str.strip():
print(f"DEBUG: Processing message: {repr(msg_str)}")
try:
msg_data = json.loads(msg_str)
message = Message(
......@@ -162,6 +168,7 @@ class SocketServer:
msg_id=msg_data['msg_id'],
data=msg_data['data']
)
print(f"DEBUG: Parsed message: {message}")
response = self.message_handler(message)
if response:
resp_data = json.dumps({
......@@ -170,9 +177,11 @@ class SocketServer:
'data': response.data
}).encode('utf-8')
client_sock.sendall(resp_data + b'\n')
except json.JSONDecodeError:
except json.JSONDecodeError as e:
print(f"DEBUG: JSON decode error: {e}")
pass
except:
except Exception as e:
print(f"DEBUG: Exception in _handle_client: {e}")
pass
finally:
client_sock.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment