2
« on: September 08, 2009, 02:34:37 am »
Hello, I am using the SelectorTCP for a basic multi-client server, and a fairly important problem arises when it's time to process the information the client sends : I cannot determine from which client the information arrives.
My question is, how would you go about recuperating the IP address from the SocketTCP?
sf::SocketTCP Socket = Selector.GetSocketReady(i);
if (Socket == Listener)
{
sf::IPAddress Address;
sf::SocketTCP Client;
Listener.Accept(Client, &Address);
std::cout << "Client connected ! (" << Address << ")" << std::endl;
//I get that the address of the Client is in Address at this point, but this doesn't solve the issue that arises when he sends information later on
Selector.Add(Client);
}
else
{
sf::Packet Packet;
if (Socket.Receive(Packet) == sf::Socket::Done)
{
//This is where i'd like to know the IP of the client who just sent the message, so I can send it back to the rest of the program
std::string Message;
Packet >> Message;
std::cout << "A client says : \"" << Message << "\"" << std::endl;
}
else
{
Selector.Remove(Socket);
}
}
Thank you for any help or advice.