Difference between localhost and the ip address

To answer your question.

127.0.0.1 is not just a different ip address to the machine ip address, it's a different interface as well. 127.0.0.1 should not be seen on the local network. It's a special internal IP address for the loopback adapter.

x.x.x.x will be your ethernet card.

by the way 'localhost' is simply an entry in your hosts file that points to 127.0.0.1

If you bind a socket to 127.0.0.1:8200 then only clients running locally will be able to access it and only with http://127.0.0.1:8200 or http://localhost:8200 (or a dns or hosts file entry that points to 127.0.0.1).

A socket bound to x.x.x.x:8200 will only be available through http://x.x.x.x:8200 or a dns or hosts file entry that points to that.

Binding a socket to 127.0.0.1 does not automatically make it available on the ethernet interface as well.

Thats why you can't connect to x.x.x.x:8200

You can bind port 8200 to all available interfaces (0.0.0.0) then it should work.

Other features of the loopback adapter:

The loopback interface is a virtual interface. It's often used to allow programs to talk to each other on the same machine. It is not a way to reference the machine IP address. 127.0.0.1 IS the IP address of the loopback virtual adaptor.

The other thing about the loopback adapter is that because it's virtual it doesn't actually pass any packets through to the network card.


For example wikepedia says that 'pointing a web browser to the URLs http://127.0.0.1/ or http://localhost/ will access that computer's own web site'

Slightly inaccurate. It may do so. Equally well it may not bring up any website and it is even possible to display an different internal website from what you get when you use your x.x.x.x address.

127.0.0.1 points to your own machine, but that doesn't mean it will behave the same way once it reaches your machine

If you want a non-technical analogy, your can consider them different doors into your house.

There are both pointing to the same house but they are not the same thing. It is possible for each door to take you into the same room or they could take you into a different room. It is also possible to lock one door and not the other.

When you configure a website, you specify which addresses to bind to and quite often the answer is all addresses. (That is equivalent to have all doors taking you into the one room)

You can also specify the website to bind to one address only. (That is equivalent to locking all doors except one.)

If you have two (or more) websites you can bind them to separate addresses. (That is equivalent to having each door going into separate rooms).

An example of how both references work, my Windows 7 computer has IIS installed, when I go into IIS Manager and right click on Default Web Site, it gives me a 'Edit Bindings' menu option. Selecting that bring up a list of bindings. I have only one, but for IP Address it has * which means IIS listens on all my ip addresses.

Tags:

Sockets

Tcpip