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

Author Topic: Can't establish a TCP connection through localhost on my Linux PC.  (Read 10406 times)

0 Members and 1 Guest are viewing this topic.

zukonake

  • Newbie
  • *
  • Posts: 6
    • View Profile
Okay so, there is this sample code: https://pastebin.com/1VWaxyif
I can't get it working on my Gentoo Linux, tried to compile it with clang++, g++, nothing works.
My firewall is disabled and I have not encountered any problems like that earlier.

The situation is as follows:
I start the server.
server says: Listening, Accepting
I start the client.
client says: Connecting
And there it freezes. The client cannot connect. If I don't start the server at all:
client says: Client does not werk. Client end
So there is some kind of connection going on, but not really.

I asked on the IRC, people said it worked for them. My friend on Windows was also able to make the connection.
I have pinpointed the issue to be server side. I have no problems with this code:
http://www.linuxhowtos.org/data/6/server.c
http://www.linuxhowtos.org/data/6/client.c
It goes through the accepting phase successfully.
Now, the SFML client also connects to the C server provided earlier.
Seems like the issue is on server side, more precisely: the TcpListener::listen and/or TcpListener::accept.
It seems that this actually SFML's bug, even though only I experience that behavior.

I also tried to connect with the C client to SFML server. Did not work. Netcat connection neither.
I am using SFML from Gentoo's repositories, I also tried to use the site-provided libs, they didn't work.
I also compiled and installed SFML from the master branch on github. No luck either.
I have run out of ideas now. I am quite certain that this is a bug.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #1 on: July 16, 2017, 07:34:43 pm »
If you don't provide an IP to listen on, TCPSocket will use 0.0.0.0 by default. Unless configured that way, 0.0.0.0 will only listen to requests from extern. Any local connection won't be listened to. If you want to operate locally, you'll have use localhost or 127.0.0.1 for the server or connect to the local IP address of your PC (not 127.0.0.1).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

zukonake

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #2 on: July 16, 2017, 11:19:44 pm »
It seems I was looking at the wrong version of the documentation. Indeed the was server listening on 0.0.0.0, but now I also tried it with "localhost" or "127.0.0.1", the issue still persists. I also tried to connect with the client to my local IP (192.168.X.X.), does not help.

zukonake

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #3 on: July 18, 2017, 09:30:50 pm »
So, any ideas or should I file an issue on github?

Gleade

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #4 on: July 19, 2017, 01:02:16 am »
I still don't think we've got enough information to come to the conclusion of it being a bug. If the problem appears to be within the server which isn't using SFML, then we can't rule out that the code itself might not be compatible with a TCP client that SFML creates. It almost sounds as if in your scenario the client was refused. Have you tried a SFML server/client connecting to the localhost?

I haven't looked at the SFML networking source code; you may have to debug the SFML source to see what is required.

One also begs the question on why you are bothering to not use SFML for both server & client?

Edit:

Sorry, I noticed in your C++ example you had both SFML server/client. It just wasn't specified in your scenario. So did you actually test the SFML server/client together?
« Last Edit: July 19, 2017, 01:18:29 am by Gleade »

zukonake

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #5 on: July 20, 2017, 12:23:03 am »
I use SFML server and client together. I only tried to use some other implementations to pinpoint the issue. Literally everything is working well together, except for SFML server.

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #6 on: July 22, 2017, 07:11:48 pm »
Just looked at the version in Gentoo's repos - 2.3.2.

Have you tried Gentoo's latest testing version (2.4.2) or compiling SFML yourself?

FWIW, I had no issues running your example on Arch Linux.

zukonake

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #7 on: July 23, 2017, 02:25:18 am »
From what I see, I have version 2.4.2 installed. I don't know if there is point in trying to compile it myself, Gentoo does that for me + I have tried to use precompiled libs from the site (also 2.4.2) as well.

codedude

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #8 on: August 04, 2017, 02:27:07 pm »
Have you tried :
sf::IpAddress localIp("127.0.0.1");
if (server.listen(55000, localIp) == Socket::Error) {
    // Smth's wrong
}
 

If it's still not working, it comes from your linux configuration. Do you have gentoo with Linux or FreeBSD ? FreeBSD can be the problem...
« Last Edit: August 04, 2017, 02:59:29 pm by codedude »

zukonake

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #9 on: August 09, 2017, 05:17:13 am »
I am using Gentoo Linux.
This part works, no error is thrown and the server actually listens (though it still won't accept any connections).
It's hard for me to believe that this is a result of my linux configurations, if I have never encountered problems with any other programs AND other implementations of networking work, only SFML's implementation does not work.

kryx

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #10 on: September 02, 2017, 05:12:28 pm »
Hello,

I don't know if you prefer a new post or a post following this topic...

I have exactly the same problem with the network package, but on Windows 10 :/

I have a server that is listening on 127.0.0.1:9000 and a client that try to connect to 127.0.0.1:9000, but the application crash at this point. No error, no exceptions.

The debugger of Visual Studio show me a stack inside msvc120.dll, but no code source from sfml or from me :/

Server:

Code: [Select]
        sf::TcpListener listener;
        listener.setBlocking(false);
        if (listener.listen(9000) != sf::Socket::Done) {
            LOG_ERROR("Unable to start listening on port ", 9000);
        }
        socket = new sf::TcpSocket();
        if (listener.accept(*socket) == sf::Socket::Done) {
                 LOG_DBUG("OK");
        }

Client:

Code: [Select]
        socket = new sf::TcpSocket();
        sf::Socket::Status statut = socket->connect("127.0.0.1", 9000, sf::seconds(10));
//Crash after this line

Thanks for your help,

K
« Last Edit: September 02, 2017, 05:52:25 pm by kryx »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #11 on: September 02, 2017, 05:44:28 pm »
Quote
The debugger of Visual Studio show me a stack inside msvc120.dll
Can you show the full stack?
Laurent Gomila - SFML developer

kryx

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #12 on: September 02, 2017, 05:50:51 pm »
Yep, there is the stack,

http://imgur.com/a/euycZ


If you want anything else, ask for it, more code, stack or test :p


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #13 on: September 02, 2017, 06:45:24 pm »
Is it complete? It should start in your own program.
Laurent Gomila - SFML developer

kryx

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Can't establish a TCP connection through localhost on my Linux PC.
« Reply #14 on: September 02, 2017, 06:50:51 pm »
It is complete.

The crash occurs in an other thread that the main thread. This one is stucked one the line just after the "connect" function (it is a "i++" option, so nothing from there)

The application isn't doing anything else except connecting to localhost. This thread is not a thread that I have launched :/

 

anything