QTcpServer and QTcpSocker
-
Hi all,
I have a client server application, with two tcpsockets on each side. My problem is notification problem when the server disconnect its socket.
Disconnection Part 1: When the client socket disconnects from the server, I get a stateChanged signal of the server socket. That works well.
void SocketServer::onStateChanged( QAbstractSocket::SocketState state ) { switch( state ) { case QAbstractSocket::UnconnectedState: if( m_socket ) { qDebug( "Socket disconnected" ); } break; default: break; }
Disconnection part 2: After a timeout of 5 minutes, the server will close its socket due to timeout (don't ask why...). I use a similar function as above, but I don't receive a stateChanged signal.
Does anybody know why?
regards
Oliver -
I found the solution:
The socket is setup within a thread and it's waiting / blocked by QWaitCondition until a message is send. When a message is send, the thread wakes up, the socket sends the message and waits until readyRead or timeout is triggered. That's working, but after that the thread is going to wait again and the socket is blocked again, so this is why the disconnect signal didn't get through.Now I replaced the QWaitCondition by waitForDisconnect() and so the socket is not blocked anymore by the wait condition, and the disconnect signal gets through.
I think this is solved.