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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With