Gio.SocketConnection

g GObject.Object GObject.Object Gio.IOStream Gio.IOStream GObject.Object->Gio.IOStream Gio.SocketConnection Gio.SocketConnection Gio.IOStream->Gio.SocketConnection

Subclasses:Gio.TcpConnection, Gio.UnixConnection

Methods

Inherited:Gio.IOStream (11), GObject.Object (37)
Structs:GObject.ObjectClass (5)
class factory_lookup_type (family, type, protocol_id)
class factory_register_type (g_type, family, type, protocol)
  connect (address, cancellable)
  connect_async (address, cancellable, callback, *user_data)
  connect_finish (result)
  get_local_address ()
  get_remote_address ()
  get_socket ()
  is_connected ()

Virtual Methods

Inherited:Gio.IOStream (5), GObject.Object (7)

Properties

Inherited:Gio.IOStream (3)
Name Type Flags Short Description
socket Gio.Socket r/w/co The underlying Gio.Socket

Signals

Inherited:GObject.Object (1)

Fields

Inherited:GObject.Object (1)
Name Type Access Description
parent_instance Gio.IOStream r  

Class Details

class Gio.SocketConnection(**kwargs)
Bases:Gio.IOStream
Abstract:No
Structure:Gio.SocketConnectionClass

Gio.SocketConnection is a Gio.IOStream for a connected socket. They can be created either by Gio.SocketClient when connecting to a host, or by Gio.SocketListener when accepting a new client.

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

Choosing what type of object to construct is done with the socket connection factory, and it is possible for 3rd parties to register custom socket connection types for specific combination of socket family/type/protocol using Gio.SocketConnection.factory_register_type().

To close a Gio.SocketConnection, use Gio.IOStream.close(). Closing both substreams of the Gio.IOStream separately will not close the underlying Gio.Socket.

New in version 2.22.

classmethod factory_lookup_type(family, type, protocol_id)[source]
Parameters:
Returns:

a GObject.GType

Return type:

GObject.GType

Looks up the GObject.GType to be used when creating socket connections on sockets with the specified family, type and protocol_id.

If no type is registered, the Gio.SocketConnection base type is returned.

New in version 2.22.

classmethod factory_register_type(g_type, family, type, protocol)[source]
Parameters:

Looks up the GObject.GType to be used when creating socket connections on sockets with the specified family, type and protocol.

If no type is registered, the Gio.SocketConnection base type is returned.

New in version 2.22.

connect(address, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the connection succeeded, False on error

Return type:

bool

Connect self to the specified remote address.

New in version 2.32.

connect_async(address, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously connect self to the specified remote address.

This clears the Gio.Socket :blocking flag on self’s underlying socket if it is currently set.

Use Gio.SocketConnection.connect_finish() to retrieve the result.

New in version 2.32.

connect_finish(result)[source]
Parameters:result (Gio.AsyncResult) – the Gio.AsyncResult
Raises:GLib.Error
Returns:True if the connection succeeded, False on error
Return type:bool

Gets the result of a Gio.SocketConnection.connect_async() call.

New in version 2.32.

get_local_address()[source]
Raises:GLib.Error
Returns:a Gio.SocketAddress or None on error. Free the returned object with GObject.Object.unref().
Return type:Gio.SocketAddress

Try to get the local address of a socket connection.

New in version 2.22.

get_remote_address()[source]
Raises:GLib.Error
Returns:a Gio.SocketAddress or None on error. Free the returned object with GObject.Object.unref().
Return type:Gio.SocketAddress

Try to get the remote address of a socket connection.

Since GLib 2.40, when used with Gio.SocketClient.connect() or Gio.SocketClient.connect_async(), during emission of Gio.SocketClientEvent.CONNECTING, this function will return the remote address that will be used for the connection. This allows applications to print e.g. “Connecting to example.com (10.42.77.3)…”.

New in version 2.22.

get_socket()[source]
Returns:a Gio.Socket or None on error.
Return type:Gio.Socket

Gets the underlying Gio.Socket object of the connection. This can be useful if you want to do something unusual on it not supported by the Gio.SocketConnection APIs.

New in version 2.22.

is_connected()[source]
Returns:whether self is connected
Return type:bool

Checks if self is connected. This is equivalent to calling Gio.Socket.is_connected() on self’s underlying Gio.Socket.

New in version 2.32.

Property Details

Gio.SocketConnection.props.socket
Name:socket
Type:Gio.Socket
Default Value:None
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

The underlying Gio.Socket