-
std::vector and sockets
I'm trying to write my chat client with the ability to accept and hold connections for multiple users. However, I've hit a.. problem.
I want to store the clients in a vector defined as 'vector <SOCKET> Sockets', so that I can use the very nice dynamic resizing to store a potentially infinate number of connections. However, this causes a problem.
1.) How would I go about [when a socket is closed remotely] retrieving WHICH socket in the vector is no longer valid and removing it? I thought about sending dummy data and seeing if the socket returned SOCKET_ERROR, but that doesn't seem to do what I want.
2.) If I wanted to send a message to a particular client (socket), the problem comes up again of retrieving the exact socket's value. I don't even have the /slightest/ idea of how to do this.
Any advice on where to go from here?
-
Registered User
I think that:
1) You can use erase method of vectors.
2) If you must remove a client because, for example, the client is no longer online, you will know since you send messages to specific clientes. "If I want to send messages to client 4567 but he no longer replyies me, then I must remove it".
Hope that helps!
Popular pages
Recent additions