I have a python application running on an IOT device which is receiving data over a bluetooth (pybluez) connection. I'm testing the IOT device with an android phone. Most of the protocol is small chatty packets, however, there's one operation which requires sending a larger amount of data all at once, about 58K in my current test.
It works sometimes, but more often than not it hangs waiting for additional data that never comes. I suspect this means I'm either overflowing some limited size buffer and dropping data, or the transport is unreliable and some data is being dropped.
The code I'm using to read the data looks like this:
# Read the boundary off the socket
borderDataSize = borderPoints * 16
while len(data) < borderDataSize:
newdata = client_sock.recv(4096)
data += newdata
# ... logic to process the data ...
Has anybody experienced this? I don't think i've ever seen this with my smaller chatty communications running in a loop, does this mean it's probably some sort of buffer overrun? Are there any best practices for dealing with this problem?