#include <SFML/Network.hpp>
#include <iostream>
using namespace std;
int main()
{
sf::SocketTCP Listener;
Listener.Listen(2435);
sf::SelectorTCP Selector;
cout << "Waiting for port 2435 connection" << endl;
Selector.Add(Listener);
while(true)
{
int Sockets = Selector.Wait();
cout << "Sockets: " << Sockets << endl;
for(int i = 0; i < Sockets; i++)
{
sf::SocketTCP Socket = Selector.GetSocketReady(i);
cout << "For loop after Selector.GetSocketReady(i);" << endl;
if(Socket == Listener)
{
sf::IPAddress adress;
sf::SocketTCP Client;
Listener.Accept(Client,&adress);
cout << "Address " << adress << " connected" << endl;
Selector.Add(Client);
}
else
{
sf::Packet packet;
if(Socket.Receive(packet) == sf::Socket::Done)
{
string String;
packet >> String;
cout << String << endl;
}
else
{
cout << "Disconnected" << endl;
Selector.Remove(Socket);
}
}
}
}
return EXIT_SUCCESS;
}
I can't understand some things here... Because SFML documentation sucks.
So my first question is what is:
what Selector.GetSocketReady(i) does really return?
And what is if(Socket == Listener)?
And why doesn't Socket always equal to Listener?
This is soo strange. I don't get it. It is equal to Listener just when someone connects, but after that its not...
Could someone help me understand this?