SFML Networking issue

The program should run as follows: Client sends a message to the server, server then sends that message to all clients. Right now, the server wont send any message back except the first one the client sends.

In case im not clear, here is an illustration of the output:
1
2
3
4
client Sent Message:Test A
client Received Message:Test A
client Sent Message:New Message
client Received Message:Test A


Here is the relevant code in the client and server cpp files

Server:
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	std::vector<sf::SocketTCP> SocketsReady;
	while( true )
	{
		unsigned int NbSockets = Selector.Wait();

		for (unsigned int i = 0; i < NbSockets; ++i)
		{
			//Get the current socket
			sf::SocketTCP Socket = Selector.GetSocketReady(i);

			if( Socket == socket )
			{
				// If the listening socket is ready, it means
				// that we can accept a new connection
				sf::IPAddress Address;
				sf::SocketTCP Client;
				socket.Accept(Client, &Address);
				std::cout << "Client connected! (" << Address << ")"<<std::endl;

				//Add it to the selector
				Selector.Add(Client);
			}
			else
			{
				// Else, it is a client socket se we can read 
				// the data sent from it
				sf::Packet ReceivePacket;
				if( Socket.Receive(ReceivePacket) == sf::Socket::Done)
				{
					// Extract the message and display it
					std::string ReceiveMessage;
					ReceivePacket >> ReceiveMessage;
					std::cout << "Received Message : " <<ReceiveMessage << std::endl;

					//Send the message to all clients
					for( unsigned int j = 0; j < NbSockets; ++i)
					{
						sf::Packet SendPacket;
						std::cout<<"Sending message : "<<ReceiveMessage<<std::endl;
						SendPacket << ReceiveMessage;
						if(Socket.Send(SendPacket) != sf::Socket::Done)
							std::cout<<"Error sending a message to all clients"<<std::endl;
					}
				}
				else
				{
					std::cout << "Error receiving message"<< std::endl;
					// Error : we'd better remove the scoket from the selector
					Selector.Remove(Socket);
				}
			}
		}
	}


Client:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
while( Connected )
	{
		// Let the user write a message
		std::string SendMessage;
		std::getline(std::cin, SendMessage);

		// Send it to the server
		sf::Packet SendPacket;
		SendPacket << SendMessage;
		std::cout<<"Sending message : "<<SendMessage<<std::endl;
		Connected = (socket.Send(SendPacket) == sf::Socket::Done);

		// Receive from the server
		sf::Packet ReceivePacket;
		std::string ReceiveMessage;
		if(socket.Receive(ReceivePacket) == sf::Socket::Done)
		{
			ReceivePacket >> ReceiveMessage;
			std::cout << "Received Message : "<<ReceiveMessage << std::endl;
		}

	}
Topic archived. No new replies allowed.