mirror of
https://github.com/Xevion/tcp-chat.git
synced 2025-12-06 07:16:33 -06:00
8 lines
271 B
Python
8 lines
271 B
Python
HEADER_LENGTH = 10
|
|
|
|
|
|
def prepare(message: str, encoding='ascii') -> bytes:
|
|
"""Prepares a message for sending through a socket by adding a proper header and encoding it."""
|
|
header = f'{len(message):<{HEADER_LENGTH}}'
|
|
return (header + message).encode(encoding)
|