glibmm: Gio::SocketClient Class Reference

glibmm 2.72.1

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gio::SocketClient Class Reference
Portable Network I/O Functionality

Helper for connecting to a network service. More...

`#include <giomm/socketclient.h>`

Inheritance diagram for Gio::SocketClient:
[legend]

## Public Member Functions
| SocketClient (SocketClient && src) noexcept
SocketClient & | operator= (SocketClient && src) noexcept
| ~SocketClient () noexcept override
GSocketClient * | gobj ()
| Provides access to the underlying C GObject. More...
const GSocketClient * | gobj () const
| Provides access to the underlying C GObject. More...
GSocketClient * | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
SocketFamily | get_family () const
| Gets the socket family of the socket client. More...
void | set_family (SocketFamily family)
| Sets the socket family of the socket client. More...
Socket::Type | get_socket_type () const
| Gets the socket type of the socket client. More...
void | set_socket_type (Socket::Type type)
| Sets the socket type of the socket client. More...
Socket::Protocol | get_protocol () const
| Gets the protocol name type of the socket client. More...
void | set_protocol (Socket::Protocol protocol)
| Sets the protocol of the socket client. More...
Glib::RefPtr< SocketAddress > | get_local_address ()
| Gets the local address of the socket client. More...
Glib::RefPtr< const SocketAddress > | get_local_address () const
| Gets the local address of the socket client. More...
void | set_local_address (const Glib::RefPtr< SocketAddress > & address)
| Sets the local address of the socket client. More...
Glib::RefPtr< SocketConnection > | connect (const Glib::RefPtr< SocketConnectable > & connectable, const Glib::RefPtr< Cancellable > & cancellable)
| Tries to resolve the connectable and make a network connection to it. More...
Glib::RefPtr< SocketConnection > | connect (const Glib::RefPtr< SocketConnectable > & connectable)
| A connect() convenience overload. More...
Glib::RefPtr< SocketConnection > | connect_to_host (const Glib::ustring & host_and_port, guint16 default_port, const Glib::RefPtr< Cancellable > & cancellable)
| This is a helper function for g_socket_client_connect(). More...
Glib::RefPtr< SocketConnection > | connect_to_host (const Glib::ustring & host_and_port, guint16 default_port)
| A connect_to_host() convenience overload. More...
Glib::RefPtr< SocketConnection > | connect_to_service (const Glib::ustring & domain, const Glib::ustring & service, const Glib::RefPtr< Cancellable > & cancellable)
| Attempts to create a TCP connection to a service. More...
Glib::RefPtr< SocketConnection > | connect_to_service (const Glib::ustring & domain, const Glib::ustring & service)
| A connect_to_service() convenience overload. More...
Glib::RefPtr< SocketConnection > | connect_to_uri (const Glib::ustring & uri, guint16 default_port, const Glib::RefPtr< Cancellable > & cancellable)
| This is a helper function for g_socket_client_connect(). More...
Glib::RefPtr< SocketConnection > | connect_to_uri (const Glib::ustring & uri, guint16 default_port)
| A connect_to_uri() convenience overload. More...
void | connect_async (const Glib::RefPtr< SocketConnectable > & connectable, const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot)
| This is the asynchronous version of g_socket_client_connect(). More...
void | connect_async (const Glib::RefPtr< SocketConnectable > & connectable, const SlotAsyncReady & slot)
| This is the asynchronous version of connect(). More...
Glib::RefPtr< SocketConnection > | connect_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes an async connect operation. More...
void | connect_to_host_async (const Glib::ustring & host_and_port, guint16 default_port, const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot)
| This is the asynchronous version of g_socket_client_connect_to_host(). More...
void | connect_to_host_async (const Glib::ustring & host_and_port, guint16 default_port, const SlotAsyncReady & slot)
| This is the asynchronous version of connect_to_host(). More...
Glib::RefPtr< SocketConnection > | connect_to_host_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes an async connect operation. More...
void | connect_to_service_async (const Glib::ustring & domain, const Glib::ustring & service, const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot)
| This is the asynchronous version of g_socket_client_connect_to_service(). More...
void | connect_to_service_async (const Glib::ustring & domain, const Glib::ustring & service, const SlotAsyncReady & slot)
| This is the asynchronous version of connect_to_service(). More...
Glib::RefPtr< SocketConnection > | connect_to_service_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes an async connect operation. More...
void | connect_to_uri_async (const Glib::ustring & uri, guint16 default_port, const Glib::RefPtr< Cancellable > & cancellable, const SlotAsyncReady & slot)
| This is the asynchronous version of g_socket_client_connect_to_uri(). More...
void | connect_to_uri_async (const Glib::ustring & uri, guint16 default_port, const SlotAsyncReady & slot)
| This is the asynchronous version of connect_to_uri(). More...
Glib::RefPtr< SocketConnection > | connect_to_uri_finish (const Glib::RefPtr< AsyncResult > & result)
| Finishes an async connect operation. More...
bool | get_enable_proxy () const
| Gets the proxy enable state; see g_socket_client_set_enable_proxy() More...
void | set_enable_proxy (bool enable)
| Sets whether or not client attempts to make connections via a proxy server. More...
bool | get_tls () const
| Gets whether client creates TLS connections. More...
void | set_tls (bool tls=true)
| Sets whether client creates TLS (aka SSL) connections. More...
TlsCertificateFlags | get_tls_validation_flags () const
| Gets the TLS validation flags used creating TLS connections via client. More...
void | set_tls_validation_flags (TlsCertificateFlags flags)
| Sets the TLS validation flags used when creating TLS connections via client. More...
Glib::RefPtr< ProxyResolver > | get_proxy_resolver ()
| Gets the ProxyResolver being used by client. More...
Glib::RefPtr< const ProxyResolver > | get_proxy_resolver () const
| Gets the ProxyResolver being used by client. More...
void | set_proxy_resolver (const Glib::RefPtr< ProxyResolver > & proxy_resolver)
| Overrides the ProxyResolver used by client. More...
guint | get_timeout () const
| Gets the I/O timeout time for sockets created by client. More...
void | set_timeout (guint timeout)
| Sets the I/O timeout for sockets created by client. More...
void | add_application_proxy (const Glib::ustring & protocol)
| Enable proxy protocols to be handled by the application. More...
Glib::PropertyProxy< SocketFamily > | property_family ()
| The sockets address family to use for socket construction. More...
Glib::PropertyProxy_ReadOnly< SocketFamily > | property_family () const
| The sockets address family to use for socket construction. More...
Glib::PropertyProxy< Glib::RefPtr< SocketAddress > > | property_local_address ()
| The local address constructed sockets will be bound to. More...
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< SocketAddress > > | property_local_address () const
| The local address constructed sockets will be bound to. More...
Glib::PropertyProxy< Socket::Protocol > | property_protocol ()
| The protocol to use for socket construction, or 0 for default. More...
Glib::PropertyProxy_ReadOnly< Socket::Protocol > | property_protocol () const
| The protocol to use for socket construction, or 0 for default. More...
Glib::PropertyProxy< Socket::Type > | property_type ()
| The sockets type to use for socket construction. More...
Glib::PropertyProxy_ReadOnly< Socket::Type > | property_type () const
| The sockets type to use for socket construction. More...
Glib::PropertyProxy< guint > | property_timeout ()
| The I/O timeout for sockets, or 0 for none. More...
Glib::PropertyProxy_ReadOnly< guint > | property_timeout () const
| The I/O timeout for sockets, or 0 for none. More...
Glib::PropertyProxy< bool > | property_enable_proxy ()
| Enable proxy support. More...
Glib::PropertyProxy_ReadOnly< bool > | property_enable_proxy () const
| Enable proxy support. More...
Glib::PropertyProxy< bool > | property_tls ()
| Whether to create TLS connections. More...
Glib::PropertyProxy_ReadOnly< bool > | property_tls () const
| Whether to create TLS connections. More...
Glib::PropertyProxy< TlsCertificateFlags > | property_tls_validation_flags ()
| The TLS validation flags used when creating TLS connections. More...
Glib::PropertyProxy_ReadOnly< TlsCertificateFlags > | property_tls_validation_flags () const
| The TLS validation flags used when creating TLS connections. More...
Glib::PropertyProxy< Glib::RefPtr< ProxyResolver > > | property_proxy_resolver ()
| The proxy resolver to use. More...
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< ProxyResolver > > | property_proxy_resolver () const
| The proxy resolver to use. More...
Glib::SignalProxy< void(SocketClientEvent, const Glib::RefPtr< SocketConnectable > &, const Glib::RefPtr< IOStream > &)> | signal_event ()
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object && src) noexcept
Object & | operator= (Object && src) noexcept
void * | get_data (const QueryQuark & key)
void | set_data (const Quark & key, void *data)
void | set_data (const Quark & key, void *data, DestroyNotify notify)
void | remove_data (const QueryQuark & quark)
void * | steal_data (const QueryQuark & quark)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring & property_name, const Glib::ValueBase & value)
| You probably want to use a specific property_*() accessor method instead. More...
void | get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | set_property (const Glib::ustring & property_name, const PropertyType & value)
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | get_property (const Glib::ustring & property_name, PropertyType & value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
PropertyType | get_property (const Glib::ustring & property_name) const
| You probably want to use a specific property_*() accessor method instead. More...
sigc::connection | connect_property_changed (const Glib::ustring & property_name, const sigc::slot< void()> & slot)
| You can use the signal_changed() signal of the property proxy instead. More...
sigc::connection | connect_property_changed (const Glib::ustring & property_name, sigc::slot< void()> && slot)
| You can use the signal_changed() signal of the property proxy instead. More...
void | freeze_notify ()
| Increases the freeze count on object. More...
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify(). More...
virtual void | reference () const
| Increment the reference count for this object. More...
virtual void | unreference () const
| Decrement the reference count for this object. More...
GObject * | gobj ()
| Provides access to the underlying C GObject. More...
const GObject * | gobj () const
| Provides access to the underlying C GObject. More...
GObject * | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access. More...

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...
static Glib::RefPtr< SocketClient > | create ()

## Protected Member Functions
| SocketClient ()
virtual void | on_event (SocketClientEvent event, const Glib::RefPtr< SocketConnectable > & connectable, const Glib::RefPtr< IOStream > & connection)
| This is a default handler for the signal signal_event(). More...
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams & construct_params)
| Object (GObject * castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
| ObjectBase (const char * custom_type_name)
| A derived constructor always overrides this choice. More...
| ObjectBase (const std::type_info & custom_type_info)
| This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
| ObjectBase (ObjectBase && src) noexcept
ObjectBase & | operator= (ObjectBase && src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject * castitem)
void | initialize_move (GObject * castitem, Glib::ObjectBase * previous_wrapper)

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gio::SocketClient > | wrap (GSocketClient * object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Glib::Object
Glib::RefPtr< Glib::Object > | wrap (GObject * object, bool take_copy=false)

## Additional Inherited Members
Public Types inherited from Glib::Object
using | DestroyNotify = void(*)(gpointer data)

## Detailed Description

Helper for connecting to a network service.

See also
  SocketConnection, SocketListener

SocketClient is a high-level utility class for connecting to a network host using a connection oriented socket type.

You create a SocketClient object, set any options you want, then call a sync or async connect operation, which returns a SocketConnection subclass on success.

The type of the SocketConnection object returned depends on the type of the underlying socket that is in use. For instance, for a TCP/IP connection it will be a TcpConnection.

Since glibmm 2.24:

## Constructor & Destructor Documentation

## ◆ SocketClient() [1/2]

Gio::SocketClient::SocketClient | ( | SocketClient && | src | ) |
| noexcept

## ◆ ~SocketClient()

Gio::SocketClient::~SocketClient | ( |  | ) |
| overridenoexcept

## ◆ SocketClient() [2/2]

Gio::SocketClient::SocketClient | ( |  | ) |
| protected

## Member Function Documentation

## ◆ add_application_proxy()

void Gio::SocketClient::add_application_proxy | ( | const Glib::ustring & | protocol | ) |

Enable proxy protocols to be handled by the application.

When the indicated proxy protocol is returned by the ProxyResolver, SocketClient will consider this protocol as supported but will not try to find a Proxy instance to handle handshaking. The application must check for this case by calling g_socket_connection_get_remote_address() on the returned SocketConnection, and seeing if it's a ProxyAddress of the appropriate type, to determine whether or not it needs to handle the proxy handshaking itself.

This should be used for proxy protocols that are dialects of another protocol such as HTTP proxy. It also allows cohabitation of proxy protocols that are reused between protocols. A good example is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also be use as generic socket proxy through the HTTP CONNECT method.

When the proxy is detected as being an application proxy, TLS handshake will be skipped. This is required to let the application do the proxy specific handshake.

Parameters

  protocol | The proxy protocol.

## ◆ connect() [1/2]

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect | ( | const Glib::RefPtr< SocketConnectable > & | connectable | ) |

A connect() convenience overload.

## ◆ connect() [2/2]

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect | ( | const Glib::RefPtr< SocketConnectable > & | connectable,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |

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

Upon a successful connection, a new SocketConnection 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 SocketConnection object returned depends on the type of the underlying socket that is used. For instance, for a TCP/IP connection it will be a TcpConnection.

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 Gio::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.

Since glibmm 2.22:

Parameters

  connectable | A SocketConnectable specifying the remote address.
  cancellable | Optional Cancellable object, `nullptr` to ignore.

Returns
  A SocketConnection on success, `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ connect_async() [1/2]

void Gio::SocketClient::connect_async | ( | const Glib::RefPtr< SocketConnectable > & | connectable,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | const SlotAsyncReady & | slot
| ) |  |

This is the asynchronous version of g_socket_client_connect().

You may wish to prefer the asynchronous version even in synchronous command line programs because, since 2.60, it implements RFC 8305 "Happy Eyeballs" recommendations to work around long connection timeouts in networks where IPv6 is broken by performing an IPv4 connection simultaneously without waiting for IPv6 to time out, which is not supported by the synchronous call. (This is not an API guarantee, and may change in the future.)

When the operation is finished slot will be called. You can then call g_socket_client_connect_finish() to get the result of the operation.

Since glibmm 2.22:

Parameters

  connectable | A SocketConnectable specifying the remote address.
  cancellable | A Cancellable, or `nullptr`.
  slot | A SlotAsyncReady.
  user_data | User data for the callback.

## ◆ connect_async() [2/2]

void Gio::SocketClient::connect_async | ( | const Glib::RefPtr< SocketConnectable > & | connectable,
|  | const SlotAsyncReady & | slot
| ) |  |

This is the asynchronous version of connect().

When the operation is finished slot will be called. You can then call finish() to get the result of the operation.

Parameters

  connectable | A SocketConnectable specifying the remote address.
  slot | A callback slot to call after the operation completes.

## ◆ connect_finish()

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes an async connect operation.

See g_socket_client_connect_async()

Since glibmm 2.22:

Parameters

  result | A AsyncResult.

Returns
  A SocketConnection on success, `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ connect_to_host() [1/2]

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_to_host | ( | const Glib::ustring & | host_and_port,
|  | guint16 | default_port
| ) |  |

A connect_to_host() convenience overload.

## ◆ connect_to_host() [2/2]

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_to_host | ( | const Glib::ustring & | host_and_port,
|  | guint16 | default_port,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |

This is a helper function for g_socket_client_connect().

Attempts to create a TCP connection to the named host.

host_and_port may be in any of a number of recognized formats; an IPv6 address, an IPv4 address, or a domain name (in which case a DNS lookup is performed). Quoting with [] is supported for all address types. A port override may be specified in the usual way with a colon. Ports may be given as decimal numbers or symbolic names (in which case an /etc/services lookup is performed).

If no port override is given in host_and_port then default_port will be used as the port number to connect to.

In general, host_and_port is expected to be provided by the user (allowing them to give the hostname, and a port override if necessary) and default_port is expected to be provided by the application.

In the case that an IP address is given, a single connection attempt is made. In the case that a name is given, multiple connection attempts may be made, in turn and according to the number of address records in DNS, until a connection succeeds.

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

In the event of any failure (DNS error, service not found, no hosts connectable) `nullptr` is returned and error (if non-`nullptr`) is set accordingly.

Since glibmm 2.22:

Parameters

  host_and_port | The name and optionally port of the host to connect to.
  default_port | The default port to connect to.
  cancellable | A Cancellable, or `nullptr`.

Returns
  A SocketConnection on success, `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ connect_to_host_async() [1/2]

void Gio::SocketClient::connect_to_host_async | ( | const Glib::ustring & | host_and_port,
|  | guint16 | default_port,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | const SlotAsyncReady & | slot
| ) |  |

This is the asynchronous version of g_socket_client_connect_to_host().

When the operation is finished slot will be called. You can then call g_socket_client_connect_to_host_finish() to get the result of the operation.

Since glibmm 2.22:

Parameters

  host_and_port | The name and optionally the port of the host to connect to.
  default_port | The default port to connect to.
  cancellable | A Cancellable, or `nullptr`.
  slot | A SlotAsyncReady.
  user_data | User data for the callback.

## ◆ connect_to_host_async() [2/2]

void Gio::SocketClient::connect_to_host_async | ( | const Glib::ustring & | host_and_port,
|  | guint16 | default_port,
|  | const SlotAsyncReady & | slot
| ) |  |

This is the asynchronous version of connect_to_host().

When the operation is finished slot will be called. You can then call connect_to_host_finish() to get the result of the operation.

Parameters

  host_and_port | The name and optionally the port of the host to connect to.
  default_port | The default port to connect to.
  slot | A callback slot to call after the opration completes.

## ◆ connect_to_host_finish()

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_to_host_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes an async connect operation.

See g_socket_client_connect_to_host_async()

Since glibmm 2.22:

Parameters

  result | A AsyncResult.

Returns
  A SocketConnection on success, `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ connect_to_service() [1/2]

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_to_service | ( | const Glib::ustring & | domain,
|  | const Glib::ustring & | service
| ) |  |

A connect_to_service() convenience overload.

## ◆ connect_to_service() [2/2]

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_to_service | ( | const Glib::ustring & | domain,
|  | const Glib::ustring & | service,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |

Attempts to create a TCP connection to a service.

This call looks up the SRV record for service at domain for the "tcp" protocol. It then attempts to connect, in turn, to each of the hosts providing the service until either a connection succeeds or there are no hosts remaining.

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

In the event of any failure (DNS error, service not found, no hosts connectable) `nullptr` is returned and error (if non-`nullptr`) is set accordingly.

Parameters

  domain | A domain name.
  service | The name of the service to connect to.
  cancellable | A Cancellable, or `nullptr`.

Returns
  A SocketConnection if successful, or `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ connect_to_service_async() [1/2]

void Gio::SocketClient::connect_to_service_async | ( | const Glib::ustring & | domain,
|  | const Glib::ustring & | service,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | const SlotAsyncReady & | slot
| ) |  |

This is the asynchronous version of g_socket_client_connect_to_service().

Since glibmm 2.22:

Parameters

  domain | A domain name.
  service | The name of the service to connect to.
  cancellable | A Cancellable, or `nullptr`.
  slot | A SlotAsyncReady.
  user_data | User data for the callback.

## ◆ connect_to_service_async() [2/2]

void Gio::SocketClient::connect_to_service_async | ( | const Glib::ustring & | domain,
|  | const Glib::ustring & | service,
|  | const SlotAsyncReady & | slot
| ) |  |

This is the asynchronous version of connect_to_service().

Parameters

  domain | A domain name.
  service | The name of the service to connect to
  slot | A callback slot to call after the opration completes.

## ◆ connect_to_service_finish()

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_to_service_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes an async connect operation.

See g_socket_client_connect_to_service_async()

Since glibmm 2.22:

Parameters

  result | A AsyncResult.

Returns
  A SocketConnection on success, `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ connect_to_uri() [1/2]

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_to_uri | ( | const Glib::ustring & | uri,
|  | guint16 | default_port
| ) |  |

A connect_to_uri() convenience overload.

## ◆ connect_to_uri() [2/2]

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_to_uri | ( | const Glib::ustring & | uri,
|  | guint16 | default_port,
|  | const Glib::RefPtr< Cancellable > & | cancellable
| ) |  |

This is a helper function for g_socket_client_connect().

Attempts to create a TCP connection with a network URI.

uri may be any valid URI containing an "authority" (hostname/port) component. If a port is not specified in the URI, default_port will be used. TLS will be negotiated if SocketClient::property_tls() is `true`. (SocketClient does not know to automatically assume TLS for certain URI schemes.)

Using this rather than g_socket_client_connect() or g_socket_client_connect_to_host() allows SocketClient to determine when to use application-specific proxy protocols.

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

In the event of any failure (DNS error, service not found, no hosts connectable) `nullptr` is returned and error (if non-`nullptr`) is set accordingly.

Since glibmm 2.26:

Parameters

  uri | A network URI.
  default_port | The default port to connect to.
  cancellable | A Cancellable, or `nullptr`.

Returns
  A SocketConnection on success, `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ connect_to_uri_async() [1/2]

void Gio::SocketClient::connect_to_uri_async | ( | const Glib::ustring & | uri,
|  | guint16 | default_port,
|  | const Glib::RefPtr< Cancellable > & | cancellable,
|  | const SlotAsyncReady & | slot
| ) |  |

This is the asynchronous version of g_socket_client_connect_to_uri().

When the operation is finished slot will be called. You can then call g_socket_client_connect_to_uri_finish() to get the result of the operation.

Since glibmm 2.26:

Parameters

  uri | A network uri.
  default_port | The default port to connect to.
  cancellable | A Cancellable, or `nullptr`.
  slot | A SlotAsyncReady.
  user_data | User data for the callback.

## ◆ connect_to_uri_async() [2/2]

void Gio::SocketClient::connect_to_uri_async | ( | const Glib::ustring & | uri,
|  | guint16 | default_port,
|  | const SlotAsyncReady & | slot
| ) |  |

This is the asynchronous version of connect_to_uri().

Parameters

  uri | A network URI.
  default_port | The default port to connect to.
  slot | A callback slot to call after the opration completes.

## ◆ connect_to_uri_finish()

Glib::RefPtr< SocketConnection > Gio::SocketClient::connect_to_uri_finish | ( | const Glib::RefPtr< AsyncResult > & | result | ) |

Finishes an async connect operation.

See g_socket_client_connect_to_uri_async()

Since glibmm 2.26:

Parameters

  result | A AsyncResult.

Returns
  A SocketConnection on success, `nullptr` on error.

Exceptions

  Glib::Error |

## ◆ create()

static Glib::RefPtr< SocketClient > Gio::SocketClient::create | ( |  | ) |
| static

## ◆ get_enable_proxy()

bool Gio::SocketClient::get_enable_proxy | ( |  | ) | const

Gets the proxy enable state; see g_socket_client_set_enable_proxy()

Since glibmm 2.26:

Returns
  Whether proxying is enabled.

## ◆ get_family()

SocketFamily Gio::SocketClient::get_family | ( |  | ) | const

Gets the socket family of the socket client.

See g_socket_client_set_family() for details.

Since glibmm 2.22:

Returns
  A SocketFamily.

## ◆ get_local_address() [1/2]

Glib::RefPtr< SocketAddress > Gio::SocketClient::get_local_address | ( |  | ) |

Gets the local address of the socket client.

See g_socket_client_set_local_address() for details.

Since glibmm 2.22:

Returns
  A SocketAddress or `nullptr`. Do not free.

## ◆ get_local_address() [2/2]

Glib::RefPtr< const SocketAddress > Gio::SocketClient::get_local_address | ( |  | ) | const

Gets the local address of the socket client.

See g_socket_client_set_local_address() for details.

Since glibmm 2.22:

Returns
  A SocketAddress or `nullptr`. Do not free.

## ◆ get_protocol()

Socket::Protocol Gio::SocketClient::get_protocol | ( |  | ) | const

Gets the protocol name type of the socket client.

See g_socket_client_set_protocol() for details.

Since glibmm 2.22:

Returns
  A Gio::Socket::Protocol.

## ◆ get_proxy_resolver() [1/2]

Glib::RefPtr< ProxyResolver > Gio::SocketClient::get_proxy_resolver | ( |  | ) |

Gets the ProxyResolver being used by client.

Normally, this will be the resolver returned by g_proxy_resolver_get_default(), but you can override it with g_socket_client_set_proxy_resolver().

Since glibmm 2.36:

Returns
  The ProxyResolver being used by client.

## ◆ get_proxy_resolver() [2/2]

Glib::RefPtr< const ProxyResolver > Gio::SocketClient::get_proxy_resolver | ( |  | ) | const

Gets the ProxyResolver being used by client.

Normally, this will be the resolver returned by g_proxy_resolver_get_default(), but you can override it with g_socket_client_set_proxy_resolver().

Since glibmm 2.36:

Returns
  The ProxyResolver being used by client.

## ◆ get_socket_type()

Socket::Type Gio::SocketClient::get_socket_type | ( |  | ) | const

Gets the socket type of the socket client.

See g_socket_client_set_socket_type() for details.

Since glibmm 2.22:

Returns
  A SocketFamily.

## ◆ get_timeout()

guint Gio::SocketClient::get_timeout | ( |  | ) | const

Gets the I/O timeout time for sockets created by client.

See g_socket_client_set_timeout() for details.

Since glibmm 2.26:

Returns
  The timeout in seconds.

## ◆ get_tls()

bool Gio::SocketClient::get_tls | ( |  | ) | const

Gets whether client creates TLS connections.

See g_socket_client_set_tls() for details.

Since glibmm 2.28:

Returns
  Whether client uses TLS.

## ◆ get_tls_validation_flags()

TlsCertificateFlags Gio::SocketClient::get_tls_validation_flags | ( |  | ) | const

Gets the TLS validation flags used creating TLS connections via client.

This function does not work as originally designed and is impossible to use correctly. See SocketClient::property_tls_validation_flags() for more information.

Since glibmm 2.28:

Deprecated: 2.72: Do not attempt to ignore validation errors.

Deprecated:
  Do not attempt to ignore validation errors.

Returns
  The TLS validation flags.

## ◆ get_type()

static GType Gio::SocketClient::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GSocketClient * Gio::SocketClient::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GSocketClient * Gio::SocketClient::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ gobj_copy()

GSocketClient * Gio::SocketClient::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ on_event()

virtual void Gio::SocketClient::on_event | ( | SocketClientEvent | event,
|  | const Glib::RefPtr< SocketConnectable > & | connectable,
|  | const Glib::RefPtr< IOStream > & | connection
| ) |  |
| protectedvirtual

This is a default handler for the signal signal_event().

## ◆ operator=()

SocketClient & Gio::SocketClient::operator= | ( | SocketClient && | src | ) |
| noexcept

## ◆ property_enable_proxy() [1/2]

Glib::PropertyProxy< bool > Gio::SocketClient::property_enable_proxy | ( |  | ) |

Enable proxy support.

Default value: `true`

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_enable_proxy() [2/2]

Glib::PropertyProxy_ReadOnly< bool > Gio::SocketClient::property_enable_proxy | ( |  | ) | const

Enable proxy support.

Default value: `true`

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_family() [1/2]

Glib::PropertyProxy< SocketFamily > Gio::SocketClient::property_family | ( |  | ) |

The sockets address family to use for socket construction.

Default value: Gio::SocketFamily::INVALID

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_family() [2/2]

Glib::PropertyProxy_ReadOnly< SocketFamily > Gio::SocketClient::property_family | ( |  | ) | const

The sockets address family to use for socket construction.

Default value: Gio::SocketFamily::INVALID

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_local_address() [1/2]

Glib::PropertyProxy< Glib::RefPtr< SocketAddress > > Gio::SocketClient::property_local_address | ( |  | ) |

The local address constructed sockets will be bound to.

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_local_address() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< SocketAddress > > Gio::SocketClient::property_local_address | ( |  | ) | const

The local address constructed sockets will be bound to.

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_protocol() [1/2]

Glib::PropertyProxy< Socket::Protocol > Gio::SocketClient::property_protocol | ( |  | ) |

The protocol to use for socket construction, or 0 for default.

Default value: Gio::Socket::Protocol::DEFAULT

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_protocol() [2/2]

Glib::PropertyProxy_ReadOnly< Socket::Protocol > Gio::SocketClient::property_protocol | ( |  | ) | const

The protocol to use for socket construction, or 0 for default.

Default value: Gio::Socket::Protocol::DEFAULT

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_proxy_resolver() [1/2]

Glib::PropertyProxy< Glib::RefPtr< ProxyResolver > > Gio::SocketClient::property_proxy_resolver | ( |  | ) |

The proxy resolver to use.

Since glibmm 2.36:

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_proxy_resolver() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< ProxyResolver > > Gio::SocketClient::property_proxy_resolver | ( |  | ) | const

The proxy resolver to use.

Since glibmm 2.36:

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_timeout() [1/2]

Glib::PropertyProxy< guint > Gio::SocketClient::property_timeout | ( |  | ) |

The I/O timeout for sockets, or 0 for none.

Default value: 0

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_timeout() [2/2]

Glib::PropertyProxy_ReadOnly< guint > Gio::SocketClient::property_timeout | ( |  | ) | const

The I/O timeout for sockets, or 0 for none.

Default value: 0

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_tls() [1/2]

Glib::PropertyProxy< bool > Gio::SocketClient::property_tls | ( |  | ) |

Whether to create TLS connections.

Default value: `false`

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_tls() [2/2]

Glib::PropertyProxy_ReadOnly< bool > Gio::SocketClient::property_tls | ( |  | ) | const

Whether to create TLS connections.

Default value: `false`

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_tls_validation_flags() [1/2]

Glib::PropertyProxy< TlsCertificateFlags > Gio::SocketClient::property_tls_validation_flags | ( |  | ) |

The TLS validation flags used when creating TLS connections.

The default value is Gio::TlsCertificateFlags::VALIDATE_ALL.

GLib guarantees that if certificate verification fails, at least one flag will be set, but it does not guarantee that all possible flags will be set. Accordingly, you may not safely decide to ignore any particular type of error. For example, it would be incorrect to mask Gio::TlsCertificateFlags::EXPIRED if you want to allow expired certificates, because this could potentially be the only error flag set even if other problems exist with the certificate. Therefore, there is no safe way to use this property. This is not a horrible problem, though, because you should not be attempting to ignore validation errors anyway. If you really must ignore TLS certificate errors, connect to the SocketClient::signal_event() signal, wait for it to be emitted with Gio::SocketClientEvent::TLS_HANDSHAKING, and use that to connect to TlsConnection::signal_accept_certificate().

Deprecated: 2.72: Do not attempt to ignore validation errors.

Deprecated:
  Do not attempt to ignore validation errors.

Default value: Gio::TlsCertificateFlags::UNKNOWN_CA | Gio::TlsCertificateFlags::BAD_IDENTITY | Gio::TlsCertificateFlags::NOT_ACTIVATED | Gio::TlsCertificateFlags::EXPIRED | Gio::TlsCertificateFlags::REVOKED | Gio::TlsCertificateFlags::INSECURE | Gio::TlsCertificateFlags::GENERIC_ERROR

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_tls_validation_flags() [2/2]

Glib::PropertyProxy_ReadOnly< TlsCertificateFlags > Gio::SocketClient::property_tls_validation_flags | ( |  | ) | const

The TLS validation flags used when creating TLS connections.

The default value is Gio::TlsCertificateFlags::VALIDATE_ALL.

GLib guarantees that if certificate verification fails, at least one flag will be set, but it does not guarantee that all possible flags will be set. Accordingly, you may not safely decide to ignore any particular type of error. For example, it would be incorrect to mask Gio::TlsCertificateFlags::EXPIRED if you want to allow expired certificates, because this could potentially be the only error flag set even if other problems exist with the certificate. Therefore, there is no safe way to use this property. This is not a horrible problem, though, because you should not be attempting to ignore validation errors anyway. If you really must ignore TLS certificate errors, connect to the SocketClient::signal_event() signal, wait for it to be emitted with Gio::SocketClientEvent::TLS_HANDSHAKING, and use that to connect to TlsConnection::signal_accept_certificate().

Deprecated: 2.72: Do not attempt to ignore validation errors.

Deprecated:
  Do not attempt to ignore validation errors.

Default value: Gio::TlsCertificateFlags::UNKNOWN_CA | Gio::TlsCertificateFlags::BAD_IDENTITY | Gio::TlsCertificateFlags::NOT_ACTIVATED | Gio::TlsCertificateFlags::EXPIRED | Gio::TlsCertificateFlags::REVOKED | Gio::TlsCertificateFlags::INSECURE | Gio::TlsCertificateFlags::GENERIC_ERROR

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ property_type() [1/2]

Glib::PropertyProxy< Socket::Type > Gio::SocketClient::property_type | ( |  | ) |

The sockets type to use for socket construction.

Default value: Gio::Socket::Type::STREAM

Returns
  A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

## ◆ property_type() [2/2]

Glib::PropertyProxy_ReadOnly< Socket::Type > Gio::SocketClient::property_type | ( |  | ) | const

The sockets type to use for socket construction.

Default value: Gio::Socket::Type::STREAM

Returns
  A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

## ◆ set_enable_proxy()

void Gio::SocketClient::set_enable_proxy | ( | bool | enable | ) |

Sets whether or not client attempts to make connections via a proxy server.

When enabled (the default), SocketClient will use a ProxyResolver to determine if a proxy protocol such as SOCKS is needed, and automatically do the necessary proxy negotiation.

See also g_socket_client_set_proxy_resolver().

Since glibmm 2.26:

Parameters

  enable | Whether to enable proxies.

## ◆ set_family()

void Gio::SocketClient::set_family | ( | SocketFamily | family | ) |

Sets the socket family of the socket client.

If this is set to something other than Gio::SocketFamily::INVALID then the sockets created by this object will be of the specified family.

This might be useful for instance if you want to force the local connection to be an ipv4 socket, even though the address might be an ipv6 mapped to ipv4 address.

Since glibmm 2.22:

Parameters

  family | A SocketFamily.

## ◆ set_local_address()

void Gio::SocketClient::set_local_address | ( | const Glib::RefPtr< SocketAddress > & | address | ) |

Sets the local address of the socket client.

The sockets created by this object will bound to the specified address (if not `nullptr`) before connecting.

This is useful if you want to ensure that the local side of the connection is on a specific port, or on a specific interface.

Since glibmm 2.22:

Parameters

  address | A SocketAddress, or `nullptr`.

## ◆ set_protocol()

void Gio::SocketClient::set_protocol | ( | Socket::Protocol | protocol | ) |

Sets the protocol of the socket client.

The sockets created by this object will use of the specified protocol.

If protocol is Gio::Socket::Protocol::DEFAULT that means to use the default protocol for the socket family and type.

Since glibmm 2.22:

Parameters

  protocol | A Gio::Socket::Protocol.

## ◆ set_proxy_resolver()

void Gio::SocketClient::set_proxy_resolver | ( | const Glib::RefPtr< ProxyResolver > & | proxy_resolver | ) |

Overrides the ProxyResolver used by client.

You can call this if you want to use specific proxies, rather than using the system default proxy settings.

Note that whether or not the proxy resolver is actually used depends on the setting of SocketClient::property_enable_proxy(), which is not changed by this function (but which is `true` by default)

Since glibmm 2.36:

Parameters

  proxy_resolver | A ProxyResolver, or `nullptr` for the default.

## ◆ set_socket_type()

void Gio::SocketClient::set_socket_type | ( | Socket::Type | type | ) |

Sets the socket type of the socket client.

The sockets created by this object will be of the specified type.

It doesn't make sense to specify a type of Gio::Socket::Type::DATAGRAM, as GSocketClient is used for connection oriented services.

Since glibmm 2.22:

Parameters

  type | A Gio::Socket::Type.

## ◆ set_timeout()

void Gio::SocketClient::set_timeout | ( | guint | timeout | ) |

Sets the I/O timeout for sockets created by client.

timeout is a time in seconds, or 0 for no timeout (the default).

The timeout value affects the initial connection attempt as well, so setting this may cause calls to g_socket_client_connect(), etc, to fail with Gio::Error::TIMED_OUT.

Since glibmm 2.26:

Parameters

  timeout | The timeout.

## ◆ set_tls()

void Gio::SocketClient::set_tls | ( | bool | tls = `true` | ) |

Sets whether client creates TLS (aka SSL) connections.

If tls is `true`, client will wrap its connections in a TlsClientConnection and perform a TLS handshake when connecting.

Note that since SocketClient must return a SocketConnection, but TlsClientConnection is not a SocketConnection, this actually wraps the resulting TlsClientConnection in a TcpWrapperConnection when returning it. You can use g_tcp_wrapper_connection_get_base_io_stream() on the return value to extract the TlsClientConnection.

If you need to modify the behavior of the TLS handshake (eg, by setting a client-side certificate to use, or connecting to the TlsConnection::signal_accept_certificate() signal), you can connect to client's SocketClient::signal_event() signal and wait for it to be emitted with Gio::SocketClientEvent::TLS_HANDSHAKING, which will give you a chance to see the TlsClientConnection before the handshake starts.

Since glibmm 2.28:

Parameters

  tls | Whether to use TLS.

## ◆ set_tls_validation_flags()

void Gio::SocketClient::set_tls_validation_flags | ( | TlsCertificateFlags | flags | ) |

Sets the TLS validation flags used when creating TLS connections via client.

The default value is Gio::TlsCertificateFlags::VALIDATE_ALL.

This function does not work as originally designed and is impossible to use correctly. See SocketClient::property_tls_validation_flags() for more information.

Since glibmm 2.28:

Deprecated: 2.72: Do not attempt to ignore validation errors.

Deprecated:
  Do not attempt to ignore validation errors.

Parameters

  flags | The validation flags.

## ◆ signal_event()

Glib::SignalProxy< void(SocketClientEvent, const Glib::RefPtr< SocketConnectable > &, const Glib::RefPtr< IOStream > &)> Gio::SocketClient::signal_event | ( |  | ) |

Slot Prototype:
  `void on_my_event(SocketClientEvent event, const Glib::RefPtr<SocketConnectable>& connectable, const Glib::RefPtr<IOStream>& connection)`

Flags: Run Last

Emitted when client's activity on connectable changes state. Among other things, this can be used to provide progress information about a network connection in the UI. The meanings of the different event values are as follows:

- Gio::SocketClientEvent::RESOLVING: client is about to look up connectable in DNS. connection will be `nullptr`.
- Gio::SocketClientEvent::RESOLVED: client has successfully resolved connectable in DNS. connection will be `nullptr`.
- Gio::SocketClientEvent::CONNECTING: client is about to make a connection to a remote host; either a proxy server or the destination server itself. connection is the SocketConnection, which is not yet connected. Since GLib 2.40, you can access the remote address via g_socket_connection_get_remote_address().
- Gio::SocketClientEvent::CONNECTED: client has successfully connected to a remote host. connection is the connected SocketConnection.
- Gio::SocketClientEvent::PROXY_NEGOTIATING: client is about to negotiate with a proxy to get it to connect to connectable. connection is the SocketConnection to the proxy server.
- Gio::SocketClientEvent::PROXY_NEGOTIATED: client has negotiated a connection to connectable through a proxy server. connection is the stream returned from g_proxy_connect(), which may or may not be a SocketConnection.
- Gio::SocketClientEvent::TLS_HANDSHAKING: client is about to begin a TLS handshake. connection is a TlsClientConnection.
- Gio::SocketClientEvent::TLS_HANDSHAKED: client has successfully completed the TLS handshake. connection is a TlsClientConnection.
- Gio::SocketClientEvent::COMPLETE: client has either successfully connected to connectable (in which case connection is the SocketConnection that it will be returning to the caller) or has failed (in which case connection is `nullptr` and the client is about to return an error).

Each event except Gio::SocketClientEvent::COMPLETE may be emitted multiple times (or not at all) for a given connectable (in particular, if client ends up attempting to connect to more than one address). However, if client emits the SocketClient::signal_event() signal at all for a given connectable, then it will always emit it with Gio::SocketClientEvent::COMPLETE when it is done.

Note that there may be additional SocketClientEvent values in the future; unrecognized event values should be ignored.

Since glibmm 2.32:

Parameters

  event | The event that is occurring.
  connectable | The SocketConnectable that event is occurring on.
  connection | The current representation of the connection.

## Friends And Related Function Documentation

## ◆ wrap()

Glib::RefPtr< Gio::SocketClient > wrap | ( | GSocketClient * | object,
|  | bool | take_copy = `false`
| ) |  |
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.