I am using PyBluez to try to determine the bluetooth transfer speed between a raspberry pi and a phone.
I want to start a timer before socket.send(data)
and stop it after the data has been sent, to see how long it took to send the data. However, this does not work as send()
is not a blocking function and goes on to the next line of code before it has finished executing.
i.e:
start = time.time()
socket.send(data)
end = time.time()
time_taken_to_send = end - start
When I set socket.setblocking(True)
, it doesn't seem to do change the time it takes to send the data.
I dont have a huge amount of control of the code on the phone side, as this is just a preliminary test to check the bandwidth and Im just using a an app downloaded from the google play store to achieve the bluetooth connection, so I cant time the time it takes to receive the data, even though socket.recv()
is a blocking function.
Does anyone know of a way to force socket.send(data)
to be a blocking function, where it will only move on to the next line of code after the data has been sent?