I am working on a project developed in c / c ++ where a server handles several connections, I do not have much experience in this language, I would like to know how to proceed to add a SOCKET to a vector, / p>
I am working on a project developed in c / c ++ where a server handles several connections, I do not have much experience in this language, I would like to know how to proceed to add a SOCKET to a vector, / p>
You may be creating a data structure
/* Struct Client */
struct HYPNOS_STRUCT
{
SOCKET socket;
};
Then define an array vector with the structure created above.
const int MAX_CLIENTS = 50;
std::vector<HYPNOS_STRUCT> hypnos_client(MAX_CLIENTS);
So, as soon as you accept a new socket you may be accessing a position of your vector to add it!
SOCKET incoming = INVALID_SOCKET;
incoming = accept(server_socket, (struct sockaddr *)&client_info, &addrsize);
hypnos_client[i].socket = incoming;