forked from 20241144010013/20241144010013
Use byte length as data_size
This commit is contained in:
parent
055e4fa224
commit
649b5b27f7
|
@ -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:
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue