Method

GioSocketconnect

since: 2.22

Declaration

gboolean
g_socket_connect (
  GSocket* socket,
  GSocketAddress* address,
  GCancellable* cancellable,
  GError** error
)

Description

Connect the socket to the specified remote address.

For connection oriented socket this generally means we attempt to make a connection to the address. For a connection-less socket it sets the default address for g_socket_send() and discards all incoming datagrams from other sources.

Generally connection oriented sockets can only connect once, but connection-less sockets can connect multiple times to change the default address.

If the connect call needs to do network I/O it will block, unless non-blocking I/O is enabled. Then G_IO_ERROR_PENDING is returned and the user can be notified of the connection finishing by waiting for the G_IO_OUT condition. The result of the connection must then be checked with g_socket_check_connect_result().

Available since: 2.22

Parameters

address

Type: GSocketAddress

A GSocketAddress specifying the remote address.

The data is owned by the caller of the function.
cancellable

Type: GCancellable

A %GCancellable or NULL.

The argument can be NULL.
The data is owned by the caller of the function.
error

Type: GError **

The return location for a recoverable error.

The argument can be NULL.
If the return location is not NULL, then you must initialize it to a NULL GError*.
The argument will left initialized to NULL by the method if there are no errors.
In case of error, the argument will be set to a newly allocated GError; the caller will take ownership of the data, and be responsible for freeing it.

Return value

Type: gboolean

TRUE if connected, FALSE on error.