On Unix systems (but not Windows or the Mac) your program must be running as root to bind to a port between 1 and 1023.
0 is a special port number. It tells Java to pick an available port.
getLocalPort() method tells you what port the
server socket is listening on. This is useful if the client and the server have
already established a separate channel of communication over which the chosen
port number can be communicated.