Clear socket buffer

In the urscript interface module, there is no way to clear the communication socket buffer. I experienced some data left in the socket buffer after a thread was killed between a ‘socket_send’ and a ‘socket_read’. In these cases, I call the following function to clear the socket buffer :

def clear_socket_buffer(socket=“1”):
byte_in_buffer = socket_read_byte_list(1, socket, 0.002)
while(byte_in_buffer[0] >= 1):
byte_in_buffer = socket_read_byte_list(1, socket, 0.002)

It works fine, but it generates a warning ‘socket_read_byte_list() : timeout’ in Polyscope log section as the last call of socket_read_byte_list ends in a timeout.

Does anybody know a better way to clear the socket buffer?

Feature request : It would be nice to have a urscript function to clear the socket buffer and a function to get the number of bytes in the socket buffer.

Thanks :slightly_smiling_face:


Hi @m.gurtner,

You can extend the timeout, put it into a thread and then kill it before the timeout occurs.