Hello,
right now, I am writing the networking code for my project and trying to figure out how to work with a non-blocking TCP socket for the client. Whenever I try to connect to my debug server, TcpSocket::Connect() returns Socket::NotReady, but the server can already see the connection and both server and client can send/receive packets. If I call TcpSocket::Connect() again, it returns Socket::Done. The different return values for the different socket functions don't seem to be too well documented, and checking the Unix implementation source code didn't help me much either since there seem to be various causes for Socket::NotReady.
I am using Crunchbang Linux and a quite recent SFML 2.0 (shortly after the time API change was committed), here is some example code that should reproduce the issue, provided it can connect to any TCP server running at the specified IP and port.
int main()
{
sf::TcpSocket NetTCP;
NetTCP.SetBlocking(false);
switch (NetTCP.Connect("localhost", 8989, sf::Time::Zero))
{
case sf::Socket::Done:
std::cout << "Connection successful" << std::endl;
break;
case sf::Socket::Disconnected:
std::cout << "Connection refused" << std::endl;
break;
case sf::Socket::Error:
std::cout << "Socket error" << std::endl;
break;
case sf::Socket::NotReady:
std::cout << "Socket not ready" << std::endl;
break;
default:
std::cout << "Unknown Error" << std::endl;
break;
}
}
Commenting out the "SetBlocking(false)" line prints "Connection successful". Changing the timeout does not seem to have any effect.
Should I just ignore the return value of Connect() if it's NotReady? If this is just a way for the socket to say, "I am connecting, wait until I am ready", I would like to know how to poll the socket status during that time, since sockets don't appear to have any kind of "IsReady()" function.
I tried searching the forums, and found someone who had a similar issue, but apparently it was related to the fact that they were using a SocketSelector, while this client-side code is only for a single TCP socket.
As always, any help or support is greatly appreciated. ^^