Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved ] Checking that the client at the other end is retrieving the data when using QTcpSocket
koahnig last edited by
The application is an application based on QTcpServer and QTcpSocket. An external application is connecting to the server and requesting data. When the connection is established the server (my application) is sending the data continuously. The client will typically retrieve the information continuously.
However, there is an external client application which may be stop the retrieval on demand. Also on demand it will "continue" the retrieval of information. However, it basically sends another reconnect. This triggers a new socket in my application. If the stop and start sequence is repeated, each time a new socket will be added. To each of these sockets my application can write without detecting a problem. The write returns the number of bytes written and also error() does not show a problem. state() returns 3 for connected state. No indication that something has changed.
Has anybody an idea what to check in order to find out that the client is not reading the data?
alexisdm last edited by
QTcpSocket::write writes the data into a buffer which is not limited in size. To know when the data is actually sent, you can use the bytesWritten(int) signal.
For example, you could start a timer each time you call write, and stop it when that signal is received, if the timer times out, it means the client isn't reading from the socket anymore.
There can be some delay, because both the operating system and the application may be using buffers (and if the client is also using QTcpSocket, you should either explicitly set a read buffer size or open the socket with the flag QIODevice::Unbuffered because the default settings doesn't limit the size of the receive buffer).
ChrisW67 last edited by
If the client is not closing the original connection then there's no indication to the server that the client does not want to receive more information on the connection. Sounds like you have a faulty client.
koahnig last edited by
[quote author="alexisdm" date="1353974018"]QTcpSocket::write writes the data into a buffer which is not limited in size. To know when the data is actually sent, you can use the bytesWritten(int) signal.
Thanks alot this helped.
There are still bytes written for a while. This might be around 20k. Since the amount per second is relatively small (<1k/sec) it takes some time. I guess this might be certainly dependent on OS.
I am using now a counter for the number of bytes indicated by bytesWritten signal. When this number does not increase anymore also the method bytesToWrite of QTcpSocket shows an increasing number.
A bit patience missing on my side would have solved it already :-)
[quote author="ChrisW67" date="1353998233"]If the client is not closing the original connection then there's no indication to the server that the client does not want to receive more information on the connection. Sounds like you have a faulty client.[/quote]
That reflects my opinion, but it is arguable. Unfortunately, this is one application. The question is how many are around doing the same thing.
My guess is that a different lib is used. With Qt I could not reproduce.