This may be a network programming problem rather than something to do with SFML.
The problem is going like this :
Launch the server.
Launch the client.
if(selector.isReady(listener)) is running.
Shut the client down.
Timeout is detected.
Launch the client back, without closing the server.
if(selector.isReady(listener)) isn't running.
This is the server code :
#include <iostream>
#include <list>
#include <SFML/Network.hpp>
std::vector<sf::TcpSocket*> clients;
sf::SocketSelector selector;
int main(int argc, char **argv) {
std::cout << "Update server initiated!" << std::endl;
sf::TcpListener listener;
listener.listen(90);
listener.setBlocking(false);
selector.add(listener);
while(true) {
if(selector.wait()) {
if(selector.isReady(listener)) {
sf::TcpSocket* client = new sf::TcpSocket;
if(listener.accept(*client) == sf::Socket::Done) {
clients.push_back(client);
selector.add(*client);
std::cout << "Connection from client " << client->getRemoteAddress() << "!" << std::endl;
}
} else {
std::vector<sf::TcpSocket*>::iterator it;
for(it = clients.begin(); it != clients.end(); it++) {
sf::TcpSocket* client = *it;
if(selector.isReady(*client)) {
sf::Packet packet;
if(client->receive(packet) == sf::Socket::Done) {
std::string data;
packet >> data;
std::cout << "Received data : " << data << std::endl;
if(data[0] == '0') {
std::string message = data.substr(1);
if(message == "abstergo") {
sf::Packet response;
std::string responseString = "1";
response << responseString;
std::cout << "Client " << client->getRemoteAddress() << " logged in." << std::endl;
client->send(response);
}
}
} else {
std::cout << "Timeout detected from " << (*it)->getRemoteAddress() << std::endl;
(*it)->disconnect();
selector.remove(**it);
delete (*it);
it = clients.erase(it);
it--;
}
}
}
}
}
}
std::cin.get();
return 0;
}