I have a server, after accept it is being created thread for a client, and i have problem here, when second client connects are happening strange things, packets which are send via server they are distorted, same with receiving, earlier i getting clear packets, and after connecting second client receiving packets they began to have strange characters.
Code:
..sock etc.
//bind
if(bind(server, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0)
{
perror("Fail bind");
exit(1);
}
std::cout << "=> Looking for clients..." << std::endl << std::endl;
std::vector <int> connection;
int clients = 0;
while( rc >= 0 )
{
rc = listen( server, 50);
if( rc < 0)
{
perror("listen");
close( server );
}
else
{
size = sizeof(client_addr);
client = accept( server, ( struct sockaddr * ) & client_addr, & size );
connection.push_back( client );
std::thread th(show, connection, clients);
threads.push_back(std::move(th));
clients++;
}
}
show(); - is a function that supports the game client, receives and sends packets all the time, works until the client disconnects.
Any idea how i can fix it?