Gio.SocketConnection¶
class — extends IOStream
GSocketConnection is a IOStream for a connected socket. They
can be created either by SocketClient when connecting to a host,
or by SocketListener when accepting a new client.
The type of the GSocketConnection 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 TcpConnection.
Choosing what type of object to construct is done with the socket
connection factory, and it is possible for third parties to register
custom socket connection types for specific combination of socket
family/type/protocol using SocketConnection.factory_register_type.
To close a GSocketConnection, use IOStream.close. Closing both
substreams of the IOStream separately will not close the
underlying Socket.
Methods¶
connect¶
Connect connection to the specified remote address.
Parameters:
address— aSocketAddressspecifying the remote address.cancellable— aGCancellableorNone
connect_async¶
def connect_async(self, address: SocketAddress, cancellable: Cancellable | None = ..., callback: Callable[[SocketConnection | None, AsyncResult], None] | None = ...) -> None
Asynchronously connect connection to the specified remote address.
This clears the Socket:blocking flag on connection's underlying
socket if it is currently set.
If Socket:timeout is set, the operation will time out and return
IOErrorEnum.TIMED_OUT after that period. Otherwise, it will continue
indefinitely until operating system timeouts (if any) are hit.
Use SocketConnection.connect_finish to retrieve the result.
Parameters:
address— aSocketAddressspecifying the remote address.cancellable— aGCancellableorNonecallback— aGAsyncReadyCallback
connect_finish¶
Gets the result of a SocketConnection.connect_async call.
Parameters:
result— theAsyncResult
get_local_address¶
Try to get the local address of a socket connection.
get_remote_address¶
Try to get the remote address of a socket connection.
Since GLib 2.40, when used with SocketClient.connect or
SocketClient.connect_async, during emission of
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)...".
get_socket¶
Gets the underlying Socket object of the connection.
This can be useful if you want to do something unusual on it
not supported by the SocketConnection APIs.
is_connected¶
Checks if connection is connected. This is equivalent to calling
Socket.is_connected on connection's underlying Socket.
Static functions¶
factory_lookup_type¶
@staticmethod
def factory_lookup_type(family: SocketFamily | int, type: SocketType | int, protocol_id: int) -> type | GObject.Type
Looks up the GType to be used when creating socket connections on
sockets with the specified family, type and protocol_id.
If no type is registered, the SocketConnection base type is returned.
Parameters:
family— aSocketFamilytype— aSocketTypeprotocol_id— a protocol id
factory_register_type¶
@staticmethod
def factory_register_type(g_type: type | GObject.Type, family: SocketFamily | int, type: SocketType | int, protocol: int) -> None
Looks up the GType to be used when creating socket connections on
sockets with the specified family, type and protocol.
If no type is registered, the SocketConnection base type is returned.
Parameters:
g_type— aGType, inheriting fromG_TYPE_SOCKET_CONNECTIONfamily— aSocketFamilytype— aSocketTypeprotocol— a protocol id
Properties¶
socket¶
The underlying Socket.