From 240c3e9a861014733db4a8749d36ba86465aef46 Mon Sep 17 00:00:00 2001 From: Nomads_Reach <144523850+NomadsReach@users.noreply.github.com> Date: Sun, 16 Aug 2026 00:43:31 -0400 Subject: [PATCH] Add transport-neutral client send boundary --- server/client_session.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server/client_session.py b/server/client_session.py index 399abec..f1e0e7b 100644 --- a/server/client_session.py +++ b/server/client_session.py @@ -5,10 +5,13 @@ import threading from dataclasses import dataclass, field from typing import Any +from packet_codec import EncodedPacket +from tcp_transport import send_message + @dataclass class ClientSession: - connection: socket.socket + connection: Any address: tuple[str, int] player_id: int connected_at: float @@ -61,6 +64,20 @@ class ClientSession: with self._send_lock: self.connection.sendall(payload) + def send_packet(self, encoded: EncodedPacket) -> None: + """Send one already-serialized protocol message through the active transport. + + TCP compatibility adds its newline delimiter here. Message-oriented + transports can expose ``send_encoded`` and receive the raw JSON payload + plus its delivery policy without TCP framing leaking into the protocol. + """ + with self._send_lock: + send_encoded = getattr(self.connection, "send_encoded", None) + if callable(send_encoded): + send_encoded(encoded) + return + send_message(self.connection, encoded.payload) + def to_snapshot(self) -> dict[str, Any]: with self._lock: return {