Storing SOCKET in a vector

2

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>     

asked by anonymous 13.05.2015 / 18:35

1 answer

2

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;
    
13.05.2015 / 18:37