I have an issue with socket::connect() and socket::getRemoteAddres() in non-blocking mode (SFML 2.1 32bits Windows 7).
I'm trying to use a non-blocking socket on my client, because I don't want it to block on connect() when there is no host listening on the chosen port, as it's called every frame.
Basically my update loop is something like this:
while (isRunning)
{
Update();
SendData();
}
void SendData()
{
// try to connect
// if connected then do some socket.send()
}
The problem is that getRemoteAddress doesn't return None, even though it is not connected.
The documentation states:
It the socket is not connected, this function returns sf::IpAddress::None.http://www.sfml-dev.org/documentation/2.1/classsf_1_1TcpSocket.php#a7904ca6ab9e018021e305a3aeb7a1b9aHere is how to reproduce the problem/bug:
sf::TcpSocket socket;
sf::Socket::Status socketStatus = sf::Socket::Error;
while (true)
{
if (socketStatus != sf::Socket::Done)
{
socket.disconnect();
socket.setBlocking(false);
socketStatus = socket.connect(viewerIPAddress, viewerPort);
sf::IpAddress remoteAddr = socket.getRemoteAddress();
printf("ip: %s\n", remoteAddr.toString().c_str()); // if it couldn't connect it should be None
}
}
Not that this is not exactly the code I'm running, I don't have a while loop trying to connect again and again, it's done only once per SendData() call, but this simpler example showcases the problem.
I was relying on what documentation says to know if my socket was connected (so I could send the data or try again to connect, without blocking the execution of the program).
Thanks for the help.