I have a question about downloading the list of connected clients of the c++ sockets, how to send the first connected client information about the other one who connected right after it?
the first client connects, writes the socket to std::vector <int> connection using connection.push_back (socket)
starts a thread, then it increases by one int clients. When the second client connects, puts socket into the vector, runs the thread, increases clients++ and has all the information about the first client, and the client first has no information about the second client, the vector connection does not change, nor does the clients increase.
The second client can send the message to himself and the client first using the for loop (int i = 0; i <clients + 1; i ++) send ("message"), but the client can only do the same for himself, how to deal with it?
global variables:
std::vector <int> connection;
int clients;
code:
size = sizeof(client_addr);
client = accept( server, ( struct sockaddr * ) & client_addr, & size );
connection.push_back(client);
//thread
if(!fork())
{
Client hClient;
hClient.Thread();
}
//thread
clients++;