Gio.SocketListener¶
- Subclasses:
 
Methods¶
- Inherited:
 - Structs:
 
class  | 
  | 
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
Virtual Methods¶
- Inherited:
 
  | 
|
  | 
Properties¶
Name  | 
Type  | 
Flags  | 
Short Description  | 
|---|---|---|---|
r/w/c  | 
Signals¶
- Inherited:
 
Name  | 
Short Description  | 
|---|---|
Emitted when listener's activity on socket changes state.  | 
Fields¶
- Inherited:
 
Name  | 
Type  | 
Access  | 
Description  | 
|---|---|---|---|
parent_instance  | 
r  | 
Class Details¶
- class Gio.SocketListener(**kwargs)¶
 - Bases:
 - Abstract:
 No
- Structure:
 
A
GSocketListeneris an object that keeps track of a set of server sockets and helps you accept sockets from any of the socket, either sync or async.Add addresses and ports to listen on using [method`Gio`.SocketListener.add_address] and [method`Gio`.SocketListener.add_inet_port]. These will be listened on until [method`Gio`.SocketListener.close] is called. Dropping your final reference to the
GSocketListenerwill not cause [method`Gio`.SocketListener.close] to be called implicitly, as some references to theGSocketListenermay be held internally.If you want to implement a network server, also look at [class`Gio`.SocketService] and [class`Gio`.ThreadedSocketService] which are subclasses of
GSocketListenerthat make this even easier.New in version 2.22.
- classmethod new()[source]¶
 - Returns:
 a new
Gio.SocketListener.- Return type:
 
Creates a new
Gio.SocketListenerwith no sockets to listen for. New listeners can be added with e.g.Gio.SocketListener.add_address() orGio.SocketListener.add_inet_port().New in version 2.22.
- accept(cancellable)[source]¶
 - Parameters:
 cancellable (
Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.- Raises:
 - Returns:
 a
Gio.SocketConnectionon success,Noneon error.- source_object:
 location where
GObject.Objectpointer will be stored, orNone
- Return type:
 (
Gio.SocketConnection, source_object:GObject.ObjectorNone)
Blocks waiting for a client to connect to any of the sockets added to the listener. Returns a
Gio.SocketConnectionfor the socket that was accepted.If source_object is not
Noneit will be filled out with the source object specified when the corresponding socket or address was added to the listener.If cancellable is not
None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLEDwill be returned.New in version 2.22.
- accept_async(cancellable, callback, *user_data)[source]¶
 - Parameters:
 cancellable (
Gio.CancellableorNone) – aGio.Cancellable, orNonecallback (
Gio.AsyncReadyCallbackorNone) – aGio.AsyncReadyCallback
This is the asynchronous version of
Gio.SocketListener.accept().When the operation is finished callback will be called. You can then call
Gio.SocketListener.accept_finish() to get the result of the operation.New in version 2.22.
- accept_finish(result)[source]¶
 - Parameters:
 result (
Gio.AsyncResult) – aGio.AsyncResult.- Raises:
 - Returns:
 a
Gio.SocketConnectionon success,Noneon error.- source_object:
 Optional
GObject.Objectidentifying this source
- Return type:
 (
Gio.SocketConnection, source_object:GObject.ObjectorNone)
Finishes an async accept operation. See
Gio.SocketListener.accept_async()New in version 2.22.
- accept_socket(cancellable)[source]¶
 - Parameters:
 cancellable (
Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.- Raises:
 - Returns:
 a
Gio.Socketon success,Noneon error.- source_object:
 location where
GObject.Objectpointer will be stored, orNone.
- Return type:
 (
Gio.Socket, source_object:GObject.ObjectorNone)
Blocks waiting for a client to connect to any of the sockets added to the listener. Returns the
Gio.Socketthat was accepted.If you want to accept the high-level
Gio.SocketConnection, not aGio.Socket, which is often the case, then you should useGio.SocketListener.accept() instead.If source_object is not
Noneit will be filled out with the source object specified when the corresponding socket or address was added to the listener.If cancellable is not
None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLEDwill be returned.New in version 2.22.
- accept_socket_async(cancellable, callback, *user_data)[source]¶
 - Parameters:
 cancellable (
Gio.CancellableorNone) – aGio.Cancellable, orNonecallback (
Gio.AsyncReadyCallbackorNone) – aGio.AsyncReadyCallback
This is the asynchronous version of
Gio.SocketListener.accept_socket().When the operation is finished callback will be called. You can then call
Gio.SocketListener.accept_socket_finish() to get the result of the operation.New in version 2.22.
- accept_socket_finish(result)[source]¶
 - Parameters:
 result (
Gio.AsyncResult) – aGio.AsyncResult.- Raises:
 - Returns:
 a
Gio.Socketon success,Noneon error.- source_object:
 Optional
GObject.Objectidentifying this source
- Return type:
 (
Gio.Socket, source_object:GObject.ObjectorNone)
Finishes an async accept operation. See
Gio.SocketListener.accept_socket_async()New in version 2.22.
- add_address(address, type, protocol, source_object)[source]¶
 - Parameters:
 address (
Gio.SocketAddress) – aGio.SocketAddresstype (
Gio.SocketType) – aGio.SocketTypeprotocol (
Gio.SocketProtocol) – aGio.SocketProtocolsource_object (
GObject.ObjectorNone) – OptionalGObject.Objectidentifying this source
- Raises:
 - Returns:
 Trueon success,Falseon error.- effective_address:
 location to store the address that was bound to, or
None.
- Return type:
 (
bool, effective_address:Gio.SocketAddress)
Creates a socket of type type and protocol protocol, binds it to address and adds it to the set of sockets we’re accepting sockets from.
Note that adding an IPv6 address, depending on the platform, may or may not result in a listener that also accepts IPv4 connections. For more deterministic behavior, see
Gio.SocketListener.add_inet_port().source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to.
If successful and effective_address is non-
Nonethen it will be set to the address that the binding actually occurred at. This is helpful for determining the port number that was used for when requesting a binding to port 0 (ie: “any port”). This address, if requested, belongs to the caller and must be freed.Call
Gio.SocketListener.close() to stop listening on address; this will not be done automatically when you drop your final reference to self, as references may be held internally.New in version 2.22.
- add_any_inet_port(source_object)[source]¶
 - Parameters:
 source_object (
GObject.ObjectorNone) – OptionalGObject.Objectidentifying this source- Raises:
 - Returns:
 the port number, or 0 in case of failure.
- Return type:
 
Listens for TCP connections on any available port number for both IPv6 and IPv4 (if each is available).
This is useful if you need to have a socket for incoming connections but don’t care about the specific port number.
source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to.
New in version 2.24.
- add_inet_port(port, source_object)[source]¶
 - Parameters:
 port (
int) – an IP port number (non-zero)source_object (
GObject.ObjectorNone) – OptionalGObject.Objectidentifying this source
- Raises:
 - Returns:
 - Return type:
 
Helper function for
Gio.SocketListener.add_address() that creates a TCP/IP socket listening on IPv4 and IPv6 (if supported) on the specified port on all interfaces.source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to.
Call
Gio.SocketListener.close() to stop listening on port; this will not be done automatically when you drop your final reference to self, as references may be held internally.New in version 2.22.
- add_socket(socket, source_object)[source]¶
 - Parameters:
 socket (
Gio.Socket) – a listeningGio.Socketsource_object (
GObject.ObjectorNone) – OptionalGObject.Objectidentifying this source
- Raises:
 - Returns:
 - Return type:
 
Adds socket to the set of sockets that we try to accept new clients from. The socket must be bound to a local address and listened to.
source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to.
The socket will not be automatically closed when the self is finalized unless the listener held the final reference to the socket. Before GLib 2.42, the socket was automatically closed on finalization of the self, even if references to it were held elsewhere.
New in version 2.22.
- set_backlog(listen_backlog)[source]¶
 - Parameters:
 listen_backlog (
int) – an integer
Sets the listen backlog on the sockets in the listener. This must be called before adding any sockets, addresses or ports to the
Gio.SocketListener(for example, by callingGio.SocketListener.add_inet_port()) to be effective.See
Gio.Socket.set_listen_backlog() for detailsNew in version 2.22.
- do_changed() virtual¶
 virtual method called when the set of socket listened to changes
- do_event(event, socket) virtual¶
 - Parameters:
 event (
Gio.SocketListenerEvent) –socket (
Gio.Socket) –
Signal Details¶
- Gio.SocketListener.signals.event(socket_listener, event, socket)¶
 - Signal Name:
 event- Flags:
 - Parameters:
 socket_listener (
Gio.SocketListener) – The object which received the signalevent (
Gio.SocketListenerEvent) – the event that is occurringsocket (
Gio.Socket) – theGio.Socketthe event is occurring on
Emitted when listener's activity on socket changes state. Note that when listener is used to listen on both IPv4 and IPv6, a separate set of signals will be emitted for each, and the order they happen in is undefined.
New in version 2.46.