...

>

Programming for Multiple Networks

Programming for Multiple Networks

Learn about application listening from a socket, multihomed servers, and physical hosts.

Listening on a socket

This multitude of interfaces affects the application software. By default, an application that listens on a socket will listen for connection attempts on any interface. Language libraries always have an “easy” version of listening on a socket. The easy version just opens a socket on every interface on the host. Bad news! Instead, we have to do it the hard way and specify which IP address we are opening the socket for:

C++
ln, err := net.Listen("tcp", ":8080") // Bad approach
ln, err := net.Listen("tcp", "spock.example.com:8080") // Good approach

To determine which interfaces to bind to, the application must be told its own name or IP addresses. This is a big difference with multihomed servers. In development, the server can always call its language-specific version of ...