Gio.SocketClient.connect

### Method

# Gio SocketClientconnect

since: 2.22

#### Declaration

    GSocketConnection*
    g_socket_client_connect (
      GSocketClient* client,
      GSocketConnectable* connectable,
      GCancellable* cancellable,
      GError** error
    )

#### Description

Tries to resolve the `connectable` and make a network connection to it.

Upon a successful connection, a new `GSocketConnection` is constructed and returned. The caller owns this new object and must drop their reference to it when finished with it.

The type of the `GSocketConnection` object returned depends on the type of the underlying socket that is used. For instance, for a TCP/IP connection it will be a `GTcpConnection`.

The socket created will be the same family as the address that the `connectable` resolves to, unless family is set with `g_socket_client_set_family()` or indirectly via g_socket_client_set_local_address(). The socket type defaults to `G_SOCKET_TYPE_STREAM` but can be set with g_socket_client_set_socket_type().

If a local address is specified with `g_socket_client_set_local_address()` the socket will be bound to this address before connecting.

Available since: 2.22

#### Parameters

`connectable`

  Type: `GSocketConnectable`

  A `GSocketConnectable` specifying the remote address.

  The data is owned by the caller of the method.

`cancellable`

  Type: `GCancellable`

  Optional `GCancellable` object, `NULL` to ignore.

  The argument can be `NULL`.
  The data is owned by the caller of the method.

`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 be 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: `GSocketConnection`

A `GSocketConnection` on success, `NULL` on error.

The caller of the method takes ownership of the data, and is responsible for freeing it.