PDA

View Full Version : QTcpSocket doesn't recognize network errors! That's bad! Maybe an bug?



jackmack
23rd July 2010, 11:22
Hi there,

I use the QTcpSocket and QTcpServer classes in my application.
My application has to make sure that the communication always is ok. If some network error occurs like connection abort the I thougt QTcpSocket recognizes that.

But NO! You can simple test it with unplugging the network cable on client side. NO stateChange() or error() is called.
If you unplug the cable on your PC then it's recognized (I think this done by checking hardware directly).

Also if I set the TCP_KEEPALIVE option there is no diffrent. Default setting of KEEPALIVE is 2 hours!!! on windows. I think only enabling KEEPALIVE is poor. You have additional set the timeouts of that function.

I wonder me also why the stateChanged() signal is sent if client aborts but if client connects there is no stateChanged() sent.

A solution is to use a "heartbeat" telegram. But this should done tcp/ip levels and not on users level.

Any experince?

squidge
23rd July 2010, 14:10
QTCPSocket recognises some errors, but others can not be detected until you actually try and send data. So in your protocol you should implement heartbeat to test that you can a) send data and b) that the host is still there and replying. It is not upto the network stack to continually test the connection. If you require such functionality you need to implement it.