/dev/rob0 writes:
That's the part I don't know, but I've heard that connecting to a socket differs from making a TCP connection to localhost.
(They're both sockets. There are many kinds of sockets, including TCP sockets and unix-domain ones.)
Yes, there is a difference. A TCP connection to localhost uses a (ip,port,ip,port) tuple for identifying the connection, whereas a unix-domain connection uses a file name, so it's affected by chroot(), directory permissions, etc. A TCP connection, on the other hand, is affected by packet filter rules.
There's also a small performance difference. Which side is faster depends on OS and version. Doesn't matter, anyway, they're both far too fast to ever be a bottleneck.
Arnt