Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::TcpSocket::connect always returns sf::Socket::Done?  (Read 4700 times)

0 Members and 1 Guest are viewing this topic.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
sf::TcpSocket::connect always returns sf::Socket::Done?
« 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

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: sf::TcpSocket::connect always returns sf::Socket::Done?
« Reply #1 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;
}
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: sf::TcpSocket::connect always returns sf::Socket::Done?
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: sf::TcpSocket::connect always returns sf::Socket::Done?
« Reply #3 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).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything