The problem is that i don't know how much bytes i will receive from socket, so i just trying to loop.
buffer = ''
while True:
data, addr = sock.recvfrom(1024)
buffer += data
print buffer
As I understood recvfrom
return only specified size of bytes and the discards other data, is it possible somehow continuously read this data to buffer variable?
It wont discard the data, it will just return the data in the next iteration. What you are doing in your code is perfectly correct.
The only thing I would change is a clause to break the loop:
buffer = ''
while True:
data, addr = sock.recv(1024)
if data:
buffer += data
print buffer
else:
break
An empty string signifies the connection has been broken according to the documentation
If this code still does not work then it would be good to show us how you are setting up your socket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With