bind


Description:

public bool bind (SocketAddress address, bool allow_reuse) throws Error

When a socket is created it is attached to an address family, but it doesn't have an address in this family.

bind assigns the address (sometimes called name) of the socket.

It is generally required to bind to a local address before you can receive connections. (See listen and accept ). In certain situations, you may also want to bind a socket that will be used to initiate connections, though this is not normally required.

If this is a TCP socket, then allow_reuse controls the setting of the `SO_REUSEADDR` socket option; normally it should be true for server sockets (sockets that you will eventually call accept on), and false for client sockets. ( Failing to set this flag on a server socket may cause bind to return g_io_error_address_in_use if the server program is stopped and then immediately restarted.)

If this is a UDP socket, then allow_reuse determines whether or not other UDP sockets can be bound to the same address at the same time. In particular, you can have several UDP sockets bound to the same address, and they will all receive all of the multicast and broadcast packets sent to that address. (The behavior of unicast UDP packets to an address with multiple listeners is not defined.)

Parameters:

this

a Socket.

address

a SocketAddress specifying the local address.

allow_reuse

whether to allow reusing this address

Returns:

true on success, false on error.