Use byte length as data_size

This commit is contained in:
20241144010020 2024-11-30 10:09:17 -03:00
parent 055e4fa224
commit 649b5b27f7
1 changed files with 2 additions and 9 deletions

View File

@ -23,18 +23,11 @@ class Networking:
Sends the size of the data before sending the data.
"""
sock.send(str(len(data)).encode())
data_len = str(len(bytes(data, "utf-8"))).encode()
sock.send(data_len)
response = sock.recv(1024).decode()
sock.send(data.encode())
def recv_any_size(self, client):
"""
Receives data from the client without knowing the size of the data.
Client must send the size of the data before sending the data.
"""
data_size = client.recv(1024).decode()
data = client.recv(int(data_size)).decode()
return data
class Server:
"""