When i create listener and make him listen for incoming connection, he waits and when connection arrives he accepts connection and everything is good.
But when i set listener to non-blocking mode my console window gets spamed with error messages that listener cant listen to specific port, but when i try to connect he accepts the connection from client.
This is minimal example of my code.
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
sf::Clock clock;
sf::Time deltaTime = sf::seconds(1.f / 60.f);
sf::Time timeSinceLastUpdate = sf::Time::Zero;
sf::TcpListener listener;
listener.setBlocking(false);
sf::TcpSocket sockets[3];
for (int i = 0; i < 3 ; i++)
{
sockets[i].setBlocking(false);
}
int socketCounter = 0;
while (true)
{
timeSinceLastUpdate += clock.restart();
while (timeSinceLastUpdate > deltaTime)
{
timeSinceLastUpdate -= deltaTime;
//60 fps....
listener.listen(27100);
if (listener.accept(sockets[socketCounter]) == sf::Socket::Done)
{
socketCounter++;
std::cout << "Player Connected";
}
}
//max fps...
}
return 0;
}