When implementing servers, for both TCP and UDP, it is important to bind the listening socket to a local address and port. If the socket isn't bound, then clients can't know where to connect.
It is also possible to use bind() on the client side to associate a socket with a particular address and port. It is sometimes useful to use bind() in this manner on machines that have multiple network interfaces. The use of bind() can allow the selection of which network address to use for the outgoing connection.
Sometimes, bind() is used to set the local port for an outgoing connection. This is usually a bad idea for a few reasons. First, it very seldom serves any purpose. The port number presented to the connected server is likely to be different because of network address translation regardless. Binding to a local port also invites the error...