Imagine that you need to test your client-server or peer-to-peer application with yourself, your machine is not connected to the Internet, does not have a real IP, and the network protocol is TCP / IP. What address would you use to connect with yourself?
Well, the IETF has long written to RFC 5735, which, among other things, defines special IP addresses, such as this, 127.0.0.1
, called loopback . It is a fixed address that always points to the machine itself. Using the localhost
domain results in the same, because in the hosts
file of the operating system localhost
is mapped to 127.0.0.1
.
The application never takes care of the network. It makes no difference whether you are running the client and server on the same machine or on different machines. It will just get the IP configuration and port passed to it and ask the operating system to send the communication. But when you send something to 127.0.0.1
, the operating system does not even bother to send it beyond the network card. The TCP / IP network driver passes directly to the application port.
There are other minor utilities at this address. For example, test whether the network communication protocol installed is the TCP / IP IPv4 version, with the command $ ping 127.0.0.1
. The operating system needs to understand this address.