Using localhost TCP/IP communication in a program - always safe?

  • Traffic to 127.0.0.0/8 and to ::1/128 is processed internally by the TCP/IP stack. It doesn't reach the physical network card and never leaves the computer, so it cannot be blocked by corporate firewalls.

  • Since loopback sockets are very common for IPC, good firewalls should never block it. (Windows Firewall doesn't.) However, there are some overly paranoid ones... In such cases, though, I would blame the firewall, not your software.

  • On Unix, it is possible to (accidentially) bring down the loopback interface (usually lo). Again, this is highly unusual.

  • Instead of a hardcoded port, socketpair() should be used when applicable, to avoid port collisions.

  • Even better would be to use Unix sockets on Linux and named pipes on Windows.


All these OSes support running firewall software. These could block localhost connections, although that's not very usual (in my experience).

There are lots of applications/services that do this. Just try running netstat -an on your box: chances are you will see quite a few applications with open listening sockets on 127.0.0.1.

I don't know of user settings that could prevent this from working on Linux. No idea for Windows. But again, this is a common technique.