PDA

View Full Version : client disconnected



carter88
14th October 2015, 08:47
Hello people I just programming a server / client
Data exchange with QT5 .5 and i get a question.
how can the server know that the client has closed the connection?

Atomic_Sheep
14th October 2015, 10:41
Here is a good video series to get you started with understanding how networking works.

https://www.youtube.com/watch?v=XaGXPObx2Gs&list=PLowKtXNTBypH19whXTVoG3oKSuOcw_XeW

I'm starting out with networking myself, so will be listening in to the responses :).

yeye_olive
14th October 2015, 11:30
Assuming your server is implemented with QTcpServer, every time a new client connects your code should call QTcpServer::nextPendingConnection() to obtain a QTcpSocket through which to communicate with the client. When the client disconnects, the QTcpSocket first emits error(QAbstractSocket::RemoteHostClosedError), then disconnected(). All you have to do is connect those signals to slots that handle the situation.

anda_skoa
14th October 2015, 12:03
Hello people I just programming a server / client
Data exchange with QT5 .5 and i get a question.
how can the server know that the client has closed the connection?

The socket has a disconnected() signal.

Cheers,
_