1
votes

I use QTcpSocket for getting information from server.

From my side it's necessary to connect and wait for bytes from server, and get them.

I create QTcpSocket. Connect it to host. Begin getting data, that's ok. But when, for example, I pull out the ethernet cable, there is no difference with the socket object.

I tried to connect such signals as QAbstractSocket::error() and QAbstractSocket::stateChange(), but none gives me anything at the moment of disconnection.

My task is to wait some seconds and try to reconnect, until I get a connection again.

Any advice?

1
The TCP connection isn't lost simply because the cable is disconnected. Disconnecting the cable and reconnecting it within a minute (if I recall correctly) should only appear as latency to your program, and not as a disconnect.Magnus Hoff
Does your protocol support ping-pong?Kamil Klimek

1 Answers

0
votes

I had a same problem while programming client and server project.

I used SIGNAL -> disconnected() which is emitted immediately by the client when it is disconnected.

connect(client, SIGNAL(disconnected()), this, SLOT(DisconnectMessage()));

Please try using it.