1
Network / Question about Socket Selector and UDP sockets
« on: October 24, 2015, 02:43:33 am »
I've started diving into the magic world of networking in SFML. All is fine, I got a nice UDP server and client to run. However, I read on the sfml tutorials about the socket selector class, and I started to ask myself questions. Does my server, which is one UDP socket, have to store each client as a seperate socket, or would I store the IP addresses to know who is who?
Server code (receiving and sending. very simple atm)
Server code (receiving and sending. very simple atm)
while (running)
{
if (selector.wait())
{
if (selector.isReady(socket))
{
sf::IpAddress rec;
unsigned short rPort;
sf::Packet packet;
socket.receive(packet, rec, rPort);
std::cout << "Recieved a packet from: " << rec.toString() << " " << rPort << std::endl;
std::string x;
packet >> x;
std::cout << "Packet:[ " << x << " ]" << std::endl;
}
}
}
as you can see, im using socket selector, but I'm thinking it's pointless.
{
if (selector.wait())
{
if (selector.isReady(socket))
{
sf::IpAddress rec;
unsigned short rPort;
sf::Packet packet;
socket.receive(packet, rec, rPort);
std::cout << "Recieved a packet from: " << rec.toString() << " " << rPort << std::endl;
std::string x;
packet >> x;
std::cout << "Packet:[ " << x << " ]" << std::endl;
}
}
}