Hi again .
I have a strange behavior regarding the selector.Wait() behavior :
#include "server.hpp"
cClient::cClient(sf::TcpSocket *socket, sf::Uint32 UID) {
this->socket = socket;
this->UID = UID;
}
cClient::~cClient() {
this->socket->Disconnect();
delete this->socket;
}
sf::Uint32 cClient::getUID() {
return this->UID;
}
int main() {
unsigned short Port = 1337;
sf::SocketSelector selector;
sf::TcpListener listener;
//std::list<sf::TcpSocket*> clients;
std::list<cClient> clientList;
listener.Listen(Port);
selector.Add(listener);
sf::Uint32 UID;
std::cout << "Server is listening to Port " << Port << ", waiting for connections..." << std::endl;
while (true) {
if (selector.Wait()) {
std::cout << "#" << std::endl;
if (selector.IsReady(listener)) {
std::cout << "b" << std::endl;
UID++;
sf::TcpSocket* client = new sf::TcpSocket;
if (listener.Accept(*client) == sf::Socket::Done) {
cClient newClient(client, UID);
// clients.push_back(client);
clientList.push_back(newClient);
selector.Add(*client);
std::cout << "New Client connected!" << std::endl;
}
} else {
std::cout << "or what?" << std::endl;
for ( tClientList::iterator it = clientList.begin(); it != clientList.end(); ++it ) {
sf::TcpSocket& client = *it->socket;
if ( selector.IsReady(client) ) {
sf::Packet packet;
if (client.Receive(packet) == sf::Socket::Done) {
std::string Message;
packet >> Message;
if ( Message == "qq" ) {
selector.Remove(client);
client.Disconnect();
std::cout << "Socket closed." << std::endl;
} else {
std::cout << "A client says : \"" << Message << "\"" << std::endl;
}
} else {
std::cout << "Socket Killed" << std::endl;
selector.Remove(client);
}
}
}
}
}
}
}
For some reason, the Wait() only waits until the first client is connected, after that the cout "#" never appears again, and the loop is looping endlessly (of course ).
What am I doing wrong?
Usign SFML 2 rev 1570
greets,
Spellbreajer[/code]