SFML community forums

Help => Network => Topic started by: zukonake on July 15, 2017, 09:18:53 pm

Title: Can't establish a TCP connection through localhost on my Linux PC.
Post by: zukonake on July 15, 2017, 09:18:53 pm
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.
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: eXpl0it3r 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).
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: zukonake 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.
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: zukonake on July 18, 2017, 09:30:50 pm
So, any ideas or should I file an issue on github?
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: Gleade 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?
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: zukonake 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.
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: dabbertorres 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.
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: zukonake 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.
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: codedude 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...
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: zukonake 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.
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: kryx 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
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: Laurent 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?
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: kryx on September 02, 2017, 05:50:51 pm
Yep, there is the stack,

http://imgur.com/a/euycZ
(http://imgur.com/a/euycZ)

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

Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: Laurent on September 02, 2017, 06:45:24 pm
Is it complete? It should start in your own program.
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: kryx 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 :/
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: eXpl0it3r on September 02, 2017, 07:21:08 pm
If it doesn't crash from your code, then SFML code in your code shouldn't make a difference. If you remove the SFML code, does it still crash?
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: kryx on September 02, 2017, 07:26:42 pm
I don't understand... If I remove the sfml part, I won't be able to use the socket, so there is no crash...

My application don't do anything else that launching a socket and connect to the server.
Title: Re: Can't establish a TCP connection through localhost on my Linux PC.
Post by: kryx on September 02, 2017, 09:11:12 pm
Problem solved, and it's absolutely my fault. If the socket is connected, he is deleted instead of kept (when the socket failed to connect).