Server only receives from client[0]?

Client[0]'s messages get received and relayed back to other clients perfectly through the server, but if any other client (client[1], client[2], etc.) try the server never receives their message.

Here is the code from the Server Project i think is relevant:

In main()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
for(;;sf::sleep(sf::milliseconds(50)))
	{
		// Make the selector wait for data on any socket
		if( selector.wait())
		{
			// Test the listener
			if(selector.isReady(listener))
			{
				//The listner is ready: there is a pending connection
				sf::TcpSocket* client = new sf::TcpSocket;
				if(listener.accept(*client) == sf::Socket::Done)
				{
					// Add the new client to the clients list
					clients.push_back(client);
					std::cout<<"Client <" << cliCounter << "> has connected!"<<std::endl;

					// Add the client to the selector so that we will 
					// be notified when he sends something
					selector.add(*client);

					// Send the ID number to the client
					clients[cliCounter]->send(&cliCounter, sizeof(ID));

					cliCounter++;
				}
			}
			else // The listener socket is not ready, test all other sockets (clients)
			{
					sf::Thread serverThread(&ServerThread);
					serverThread.launch();
			}
		}


in ServerThread()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

	for(;;sf::sleep(sf::milliseconds(10)))
	{
		//For all clients
		for(std::vector<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); ++it)
		{
			sf::TcpSocket& client = **it;
			if(selector.isReady(client))
			{
				// The client has sent some data,, we can receive it
				sf::Packet packet;
				if(client.receive(packet) == sf::Socket::Done)
				{
					// extract data from packet into buffer
					packet >> sbuffer;
					std::cout<<"Client<"<<sbuffer.ID<<">: "<<sbuffer.Message<<std::endl;

					// Relay message to all other clients( oC)
					for( int oC = 0; oC != cliCounter; oC++)
					{
						if(clients[oC] != clients[sbuffer.ID])
						{
							if(clients[oC]->send(packet) != sf::Socket::Done)
								std::cout<<"Error Sending message!"<<std::endl;
						}
					}
				}
			}
		}
Topic archived. No new replies allowed.