It can work, but the underlying connection architecture needs to be carefully thought out.
You can connect two machines with one socket. You can have multiple games on the single machine attaching to each other if you design it as a star, with one game acting as the central hub and the others acting as a star. It isn't what many people consider P2P, but it generally works out well enough.
Brief networking tutorial on how it works:
An IP header has four values. { Source IP, Source Port, Dest IP, Dest Port }
When a server starts listening for a connection you establish server's IP and the server's port. In your case your source IP is the loopback, and the port is whatever you assign. The server is looking for { Any IP, Any Port, loopback, port_number_you_specify }
When a client attempts to connect you establish two more. The source IP is from the client. Normally (unless you specify a port)the operating system decides the port to be any unused value. So when connecting it will look like this: { loopback, automatically_generated_unused_port, loopback, port_number_you_specify } Since automatically_generated_unused_port is different for every game client they should all be able to connect over a unique connection.
The example looks like it should work directly out of the box, so it could easily be something else. Assuming Windows, make sure the port is open in Windows Firewall or another antivirus/antispam/proxy program blocking the connection.