Advertisement

[SDLNet] Server does not receive incoming connection from client

Started by October 25, 2014 08:40 PM
2 comments, last by sheep19 10 years ago

I am making a simple Client-Server application.

For now, I am trying to create a server and a client, and make the client connect to the server. When this is done, the server should print a message.

-- Server --

http://pastebin.com/xFT3Eau4

-- Client --

http://pastebin.com/24Trvf3E

First I run the server.

Then I run the client, it prints 0.0.0.0 but the server does not seem to receive the connection request by the client. No errors are printed however (really strange...)

If I try to change the IP that the client connects to to the local IP of the pc the server is running (192.168.x.y) or to localhost I get "Couldn't connect to remote host" from the client... But why? Shouldn't these work in the same way as 0.0.0.0?

What troubles me is that with 0.0.0.0 the client seems to connect to the server (no errors by the client) but the server never receives the request. Maybe it's blocked by a firewall or am I doing something really wrong?

0.0.0.0 means "all local interfaces" when bindint a socket to local network interfaces, but it is not a valid IP address for creating/connecting connections.
enum Bool { True, False, FileNotFound };
Advertisement
A good tip for debugging networked programs is to substitute programs known to work.

For example, use the existing program "telnet" or "netcat" to simulate a TCP client (at least one is likely to be already installed on your system).

You can use many programs as a server for testing basic connectivity, you can attempt to connect to www.google.com on port 80, I believe netcat has a server mode.

With these tools, you can gain confidence as to what is expected behaviour and what could be a bug in your program.

I found the problem. On Server I should have initialized the IPaddress structure using this function:

SDLNet_ResolveHost(&ip, nullptr, 12000)

instead of setting the fields manually.

This topic is closed to new replies.

Advertisement