Managing HP Serviceguard for Linux, Eighth Edition, March 2008

Designing Highly Available Cluster Applications
Designing Applications to Run on Multiple Systems
Appendix B348
Bind to a Fixed Port
When binding a socket, a port address can be specified or one can be
assigned dynamically. One issue with binding to random ports is that a
different port may be assigned if the application is later restarted on
another cluster node. This may be confusing to clients accessing the
application.
The recommended method is using fixed ports that are the same on all
nodes where the application will run, instead of assigning port numbers
dynamically. The application will then always return the same port
number regardless of which node is currently running the application.
Application port assignments should be put in /etc/services to keep
track of them and to help ensure that someone will not choose the same
port number.
Bind to Relocatable IP Addresses
When sockets are bound, an IP address is specified in addition to the port
number. This indicates the IP address to use for communication and is
meant to allow applications to limit which interfaces can communicate
with clients. An application can bind to INADDR_ANY as an indication that
messages can arrive on any interface.
Network applications can bind to a stationary IP address, a relocatable
IP address, or INADDR_ANY. If the stationary IP address is specified, then
the application may fail when restarted on another node, because the
stationary IP address is not moved to the new system. If an application
binds to the relocatable IP address, then the application will behave
correctly when moved to another system.
Many server-style applications will bind to INADDR_ANY, meaning that
they will receive requests on any interface. This allows clients to send to
the stationary or relocatable IP addresses. However, in this case the
networking code cannot determine which source IP address is most
appropriate for responses, so it will always pick the stationary IP
address.
For TCP stream sockets, the TCP level of the protocol stack resolves this
problem for the client since it is a connection-based protocol. On the
client, TCP ignores the stationary IP address and continues to use the
previously bound relocatable IP address originally used by the client.