How to know how many bytes available to usocket.recv() ?
Thanks.
How to know how many bytes available to usocket.recv() ?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: How to know how many bytes available to usocket.recv() ?
There is no way to know in advance how many bytes will be received (as far as I know). When you issue the .recv() method you will get back as many bytes as were available in the timeout period. You can then check the size of the received bytes object or parse it and look for a delimiter.
Code: Select all
bytes_rx = my_socket.recv()
print(len(bytes_rx))
eol = bytes_rx.find(b'\n')
if eol > 0:
# Got a line of text
else:
# need to try again and concatenate
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.