6

I have a general question regarding binding and connecting to localhost. I am using a TCP client/server and on the server side I do sth of the form:

bind(localhost, 9999);
listen();

This is done on a unix host with a name e.g. host1

Now, the client is running on a separate Windows box, on the same network. In order to connect I tried to connect via hostname:port, hostIp:port but none of that succeeds.

Is this because binding to localhost is not visible across the network for other processes to connect to and is used for e.g. client/server running on the same machine?

1 Answer 1

14

If you are binding to localhost (i.e. 127.0.0.1), you can only accept connections from the localhost, not over the network.

If you need to accept remote connections over the network, you should either bind to one of the local IP addresses (e.g. 192.168.0.10) or all interfaces (i.e. 0.0.0.0).

This is due to the fact that 127.0.0.1 is always local loopback address, and as such never routed over the network.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.