SocketService

Added in version 2.22.

class SocketService(**properties: Any)

Superclasses: SocketListener, Object

Subclasses: ThreadedSocketService

Constructors:

SocketService(**properties)
new() -> Gio.SocketService

Constructors

class SocketService
classmethod new() SocketService

Creates a new SocketService with no sockets to listen for. New listeners can be added with e.g. add_address() or add_inet_port().

New services are created active, there is no need to call start(), unless stop() has been called before.

Added in version 2.22.

Methods

class SocketService
is_active() bool

Check whether the service is active or not. An active service will accept new clients that connect, while a non-active service will let connecting clients queue up until the service is started.

Added in version 2.22.

start() None

Restarts the service, i.e. start accepting connections from the added sockets when the mainloop runs. This only needs to be called after the service has been stopped from stop().

This call is thread-safe, so it may be called from a thread handling an incoming client request.

Added in version 2.22.

stop() None

Stops the service, i.e. stops accepting connections from the added sockets when the mainloop runs.

This call is thread-safe, so it may be called from a thread handling an incoming client request.

Note that this only stops accepting new connections; it does not close the listening sockets, and you can call start() again later to begin listening again. To close the listening sockets, call close(). (This will happen automatically when the SocketService is finalized.)

This must be called before calling close() as the socket service will start accepting connections immediately when a new socket is added.

Added in version 2.22.

Properties

class SocketService
props.active: bool

Whether the service is currently accepting connections.

Added in version 2.46.

Signals

class SocketService.signals
incoming(connection: SocketConnection, source_object: Object | None = None) bool

The ::incoming signal is emitted when a new incoming connection to service needs to be handled. The handler must initiate the handling of connection, but may not block; in essence, asynchronous operations must be used.

connection will be unreffed once the signal handler returns, so you need to ref it yourself if you are planning to use it.

Added in version 2.22.

Parameters:

Virtual Methods

class SocketService
do_incoming(connection: SocketConnection, source_object: Object) bool

signal emitted when new connections are accepted

Parameters:
  • connection

  • source_object

Fields

class SocketService
parent_instance
priv