diff options
| author | troido <troido@protonmail.com> | 2020-03-06 11:26:59 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-06 11:26:59 +0100 |
| commit | dd07ff4d686f07cdc9736627dd0ef099ef5e4e4f (patch) | |
| tree | f43310b3779a95efd74a40ba8139cf146ad49051 /asciifarm/common/tcommunicate.py | |
| parent | c9366616079240cd7ee3d243c9f6897d40b4267d (diff) | |
new directory structure for the separate client repo
Diffstat (limited to 'asciifarm/common/tcommunicate.py')
| -rw-r--r-- | asciifarm/common/tcommunicate.py | 32 |
1 files changed, 0 insertions, 32 deletions
diff --git a/asciifarm/common/tcommunicate.py b/asciifarm/common/tcommunicate.py deleted file mode 100644 index b1fc1b0..0000000 --- a/asciifarm/common/tcommunicate.py +++ /dev/null @@ -1,32 +0,0 @@ - -HEADER_SIZE = 4 - - -# this module is for sending discree messages over TCP -# this is achieved by prefixing all messages with their length -# calls to send and recv will also keep attempting to send all data unless this proves impossible - - -def send(sock, msg): - length = len(msg) - header = length.to_bytes(4, byteorder="big") - totalmsg = header + msg - sock.sendall(totalmsg) - -def receive(sock): - header = recvall(sock, 4) #sock.recv(4) - length = int.from_bytes(header, byteorder="big") - return recvall(sock, length) - -def recvall(sock, length): - chunks = [] - bytes_recd = 0 - while bytes_recd < length: - chunk = sock.recv(min(length - bytes_recd, 4096)) - if chunk == b'': - break - #raise RuntimeError("socket connection broken") - chunks.append(chunk) - bytes_recd = bytes_recd + len(chunk) - return b''.join(chunks) - |
