0

It goes like this : A server is running and a client is connected instantly. The client then gives his ID which is verified by server upon verification server gives green signal to the connection to send information.

Now in this verification i want to check if a particular client ID already has a verified connection or not.

At a single moment i want only one connection for a particular client ID I am programming with sockets (learning) but I don't understand how to tackle this problem.

I'm using c++.(ubuntu)

Ali Tahir
  • 379
  • 2
  • 14
  • keep a list of all connected clients (maybe a global map of string-> client) – pm100 Apr 23 '18 at 18:04
  • yes i did thought about that. but problem is how to remove the connected client from list when there is sudden unexpected disconnection. – Ali Tahir Apr 23 '18 at 18:13
  • 1
    server will receive notification that the client disconnected (assuming this is TCP) – pm100 Apr 23 '18 at 18:14
  • 1
    All [standard containers](http://en.cppreference.com/w/cpp/container) have ways of removing elements from them. – Some programmer dude Apr 23 '18 at 18:19
  • 2
    It's not entirely true that you will be notified of a disconnect. If the connection fails without proper disconnect handshaking and there are no keep-alives or regular messages that can fail, it can be a long, long, long time before death is noticed. – user4581301 Apr 23 '18 at 19:09
  • @user4581301 It can be as long as your server's read timeout. If you set that to a long, long time, you shouldn't, and if you don't set it at all, you should. – user207421 Apr 24 '18 at 08:38
  • @pm100 What would a C solution be? – Harith Jan 27 '23 at 19:33
  • @Haris - recv will return 0 length – pm100 Jan 27 '23 at 21:14
  • @pm100 on a closed connection, indeed. But I was asking about the global map. :) – Harith Jan 28 '23 at 19:17

0 Answers0