1

I have a server and a client program. I am updating the number of clients as and when a client comes. However I am unable to show which client has closed after closing. Can anybody help me? I am using socketdescriptor to keep track of clients present.

I am also having different types of clients for which I am using threading concept. When a client arrives, a Server class inheriting QTcpServer accepts connection and passes it a requesthandler class that inherits QTcpSocket. In this I am calling thread class for defining different types of clients. Here I am calling a function that updats client number in GUI. However when I close a connection I am unable to identify which client closed and thus unable to updat in client. How to overcome this issue?

NorthCat
  • 9,643
  • 16
  • 47
  • 50
guest
  • 11
  • 1
  • Can you not identify the clients by theirs IP addresses? I think its possible by getting the QTcpSocket and then getting IP by peerAddress() like its described [here](http://stackoverflow.com/questions/9204033/get-remote-host-ip-address-qtcpserver) – nayana Apr 13 '15 at 07:30

1 Answers1

1
void QAbstractSocket::disconnected() [SIGNAL]

is the way to go.

if for some case the clients are on the same machine, they must identify at the server anyway (a unique id or the type of application it is).

that might be done with a initial message to "tell the server" what kind of client is connected. that stored in a QMap<QTcpSocket*, MyClientType> and you can determine wich client disconnected and wich type it was.

cheers

Zaiborg
  • 2,492
  • 19
  • 28
  • i am running multiple servers to connect to the multiple type of clients.is this ok? and can i use socketdescriptor as unique id? – guest Apr 16 '15 at 02:31
  • if all your applications (server and client) have a unique ip address, the ip will do the trick. if multiple types of application but only one at a time for each type you have your unique id. If you just need the ui to update, i think you will be using dynamic widgets to display their state so just save wich socket pointer is linked to wich widget and update it as you please – Zaiborg Apr 16 '15 at 06:52