:right-sidebar: True SocketConnection =================================================================== .. currentmodule:: gi.repository.Gio .. versionadded:: 2.22 .. class:: SocketConnection(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gio.IOStream`, :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gio.TcpConnection`, :class:`~gi.repository.Gio.UnixConnection` ``GSocketConnection`` is a :obj:`~gi.repository.Gio.IOStream` for a connected socket. They can be created either by :obj:`~gi.repository.Gio.SocketClient` when connecting to a host, or by :obj:`~gi.repository.Gio.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 :obj:`~gi.repository.Gio.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 :obj:`~gi.repository.Gio.SocketConnection.factory_register_type`\. To close a ``GSocketConnection``\, use :obj:`~gi.repository.Gio.IOStream.close`\. Closing both substreams of the :obj:`~gi.repository.Gio.IOStream` separately will not close the underlying :obj:`~gi.repository.Gio.Socket`\. Methods ------- .. rst-class:: interim-class .. class:: SocketConnection :no-index: .. method:: connect(address: ~gi.repository.Gio.SocketAddress, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool Connect ``connection`` to the specified remote address. .. versionadded:: 2.32 :param address: a :obj:`~gi.repository.Gio.SocketAddress` specifying the remote address. :param cancellable: a %GCancellable or :const:`None` .. method:: connect_async(self, address: ~gi.repository.Gio.SocketAddress) -> bool :async: This is the `awaitable `_ version of :meth:`connect_async`. .. versionadded:: 2.32 :param address: a :obj:`~gi.repository.Gio.SocketAddress` specifying the remote address. .. method:: connect_async(address: ~gi.repository.Gio.SocketAddress, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Asynchronously connect ``connection`` to the specified remote address. This clears the :obj:`~gi.repository.Gio.Socket`\:blocking flag on ``connection``\'s underlying socket if it is currently set. If :obj:`~gi.repository.Gio.Socket`\:timeout is set, the operation will time out and return :const:`~gi.repository.Gio.IOErrorEnum.TIMED_OUT` after that period. Otherwise, it will continue indefinitely until operating system timeouts (if any) are hit. Use :func:`~gi.repository.Gio.SocketConnection.connect_finish` to retrieve the result. .. versionadded:: 2.32 :param address: a :obj:`~gi.repository.Gio.SocketAddress` specifying the remote address. :param cancellable: a %GCancellable or :const:`None` :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` :param user_data: user data for the callback .. method:: connect_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Gets the result of a :func:`~gi.repository.Gio.SocketConnection.connect_async` call. .. versionadded:: 2.32 :param result: the :obj:`~gi.repository.Gio.AsyncResult` .. classmethod:: factory_lookup_type(type: ~gi.repository.Gio.SocketType, protocol_id: int) -> ~gobject.GType Looks up the :obj:`~gi.repository.GObject.Type` to be used when creating socket connections on sockets with the specified ``family``\, ``type`` and ``protocol_id``\. If no type is registered, the :obj:`~gi.repository.Gio.SocketConnection` base type is returned. .. versionadded:: 2.22 :param type: a :obj:`~gi.repository.Gio.SocketType` :param protocol_id: a protocol id .. classmethod:: factory_register_type(family: ~gi.repository.Gio.SocketFamily, type: ~gi.repository.Gio.SocketType, protocol: int) -> None Looks up the :obj:`~gi.repository.GObject.Type` to be used when creating socket connections on sockets with the specified ``family``\, ``type`` and ``protocol``\. If no type is registered, the :obj:`~gi.repository.Gio.SocketConnection` base type is returned. .. versionadded:: 2.22 :param family: a :obj:`~gi.repository.Gio.SocketFamily` :param type: a :obj:`~gi.repository.Gio.SocketType` :param protocol: a protocol id .. method:: get_local_address() -> ~gi.repository.Gio.SocketAddress Try to get the local address of a socket connection. .. versionadded:: 2.22 .. method:: get_remote_address() -> ~gi.repository.Gio.SocketAddress Try to get the remote address of a socket connection. Since GLib 2.40, when used with :func:`~gi.repository.Gio.SocketClient.connect` or :func:`~gi.repository.Gio.SocketClient.connect_async`, during emission of :const:`~gi.repository.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)...". .. versionadded:: 2.22 .. method:: get_socket() -> ~gi.repository.Gio.Socket Gets the underlying :obj:`~gi.repository.Gio.Socket` object of the connection. This can be useful if you want to do something unusual on it not supported by the :obj:`~gi.repository.Gio.SocketConnection` APIs. .. versionadded:: 2.22 .. method:: is_connected() -> bool Checks if ``connection`` is connected. This is equivalent to calling :func:`~gi.repository.Gio.Socket.is_connected` on ``connection``\'s underlying :obj:`~gi.repository.Gio.Socket`\. .. versionadded:: 2.32 Properties ---------- .. rst-class:: interim-class .. class:: SocketConnection :no-index: .. attribute:: props.socket :type: ~gi.repository.Gio.Socket The type of the None singleton. .. versionadded:: 2.22 Fields ------ .. rst-class:: interim-class .. class:: SocketConnection :no-index: .. attribute:: parent_instance .. attribute:: priv