Socket.bind

When a socket is created it is attached to an address family, but it doesn't have an address in this family. g_socket_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 g_socket_listen() and g_socket_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. allow_reuse should be TRUE for server sockets (sockets that you will eventually call g_socket_accept() on), and FALSE for client sockets. (Specifically, if it is TRUE, then g_socket_bind() will set the SO_REUSEADDR flag on the socket, allowing it to bind address even if that address was previously used by another socket that has not yet been fully cleaned-up by the kernel. Failing to set this flag on a server socket may cause the bind call to return G_IO_ERROR_ADDRESS_IN_USE if the server program is stopped and then immediately restarted.) Since 2.22

class Socket
int
bind

Parameters

address SocketAddress

a GSocketAddress specifying the local address.

allowReuse int

whether to allow reusing this address

Return Value

Type: int

TRUE on success, FALSE on error.

Throws

GException on failure.

Meta