SFML community forums

Help => Network => Topic started by: AlexAUT on October 22, 2013, 05:51:03 pm

Title: sf::TcpSocket::connect always returns sf::Socket::Done?
Post by: AlexAUT on October 22, 2013, 05:51:03 pm
Example Code:

#include <SFML/Network.hpp>

int main()
{
   sf::TcpSocket socket;
   sf::Socket::Status status = socket.connect("192.168.0.5", 53000);
   if (status != sf::Socket::Done)
   {
      return -1;
   }

   return 0;
}
 

On my computer (Windows 8.1) this will always return 0; . I guess this isn't the expected behaviour, I tried it with serveral random IPs and it always returned "Done".

I tried it with a TimeOut aswell. The function will block the thread for the given time and then retrun sf::Socket::Done. Without a Timeout it will block the thread for a random time (near to 20seconds) and then also return sf::Socket::Done.

Do i missunderstand the API in this case? Or is it a bug?

AlexAUT
Title: Re: sf::TcpSocket::connect always returns sf::Socket::Done?
Post by: binary1248 on October 22, 2013, 07:24:45 pm
There are 2 cases we should really consider by themselves and not at the same time.

First we should try to figure out why sf::Socket::Done is returned on an unsuccessful connect() call.

What does this code output and what does it return when you run it?
#include <iostream>
#include <windows.h>
#include <SFML/Network.hpp>

int main()
{
        std::cout << SOCKET_ERROR << "\n";

        sf::TcpSocket socket;
        sf::Socket::Status status = socket.connect("192.168.0.5", 53000);

        std::cout << WSAGetLastError() << "\n";

        if (status != sf::Socket::Done)
        {
                return -1;
        }

        return 0;
}
Title: Re: sf::TcpSocket::connect always returns sf::Socket::Done?
Post by: AlexAUT on October 22, 2013, 11:46:43 pm
Strange, now it works. Didn't change anything, except a reboot... (was out watching football  :) )

btw your code doesn't work "WSAGetLastError()" is not defined. But thanks anyway!



AlexAUT
Title: Re: sf::TcpSocket::connect always returns sf::Socket::Done?
Post by: eXpl0it3r on October 23, 2013, 08:58:43 am
btw your code doesn't work "WSAGetLastError()" is not defined. But thanks anyway!
I think, you'd have to link against ws2_32 (or similar).