TCP server disconnection due to slow reading?
Posted: Tue Aug 22, 2017 8:29 pm
Hi! I am trying to write a Python 3 TPC/IP client that also does plotting and processing in real time. The example code found here works pretty well with a few modifications for Python 3. I changed the read() method to simply fetch the next packet instead of using a "duration" argument.
However things start to break down if my program has to perform work in-between the read() calls (between reading each TCP packet). In my case, simply keeping a PyQtgraph open and appending the received data to a numpy matrix in-between the read calls makes the green light on the TCP tab go from "Connected" to "Listening" after a few seconds. Interestingly, even though ActiView show the client as disconnected, my Python script still manages to continue reading data for a few seconds before hanging on the socket.recv() call.
This and other tests on your Matlab client has led me to believe that ActiView disconnects if data is read more slowly than it is collected. I hypothesize that the TCP server has some sort of buffer, and when it reaches its maximum size (because data is read more slowly by my busy program than it is generated), it simply disconnects.
Is this true? Is there any more in-depth documentation on the specifics of the TCP server? what are the conditions for a disconnection?
Also, if I were to detect the closing of the connection and simply re-open a new socket when ActiView disconnects, would data be lost (the remaining data in the server's buffer) ?
Maybe I could trying reading more that the number of bytes per TCP array each read (perhaps until no data is received?) would that work? is it guaranteed to return whole TCP arrays (a byte array that has length multiple of "bytes in TCP array")?
Any link to documentation or technical help would be appreciated
Thank you
However things start to break down if my program has to perform work in-between the read() calls (between reading each TCP packet). In my case, simply keeping a PyQtgraph open and appending the received data to a numpy matrix in-between the read calls makes the green light on the TCP tab go from "Connected" to "Listening" after a few seconds. Interestingly, even though ActiView show the client as disconnected, my Python script still manages to continue reading data for a few seconds before hanging on the socket.recv() call.
This and other tests on your Matlab client has led me to believe that ActiView disconnects if data is read more slowly than it is collected. I hypothesize that the TCP server has some sort of buffer, and when it reaches its maximum size (because data is read more slowly by my busy program than it is generated), it simply disconnects.
Is this true? Is there any more in-depth documentation on the specifics of the TCP server? what are the conditions for a disconnection?
Also, if I were to detect the closing of the connection and simply re-open a new socket when ActiView disconnects, would data be lost (the remaining data in the server's buffer) ?
Maybe I could trying reading more that the number of bytes per TCP array each read (perhaps until no data is received?) would that work? is it guaranteed to return whole TCP arrays (a byte array that has length multiple of "bytes in TCP array")?
Any link to documentation or technical help would be appreciated
Thank you