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
GSocketListener
is 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
GSocketListener
will not cause [method`Gio`.SocketListener.close] to be called implicitly, as some references to theGSocketListener
may 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
GSocketListener
that make this even easier.New in version 2.22.
- classmethod new()[source]¶
- Returns:
a new
Gio.SocketListener
.- Return type:
Creates a new
Gio.SocketListener
with 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.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore.- Raises:
- Returns:
a
Gio.SocketConnection
on success,None
on error.- source_object:
location where
GObject.Object
pointer will be stored, orNone
- Return type:
(
Gio.SocketConnection
, source_object:GObject.Object
orNone
)
Blocks waiting for a client to connect to any of the sockets added to the listener. Returns a
Gio.SocketConnection
for the socket that was accepted.If source_object is not
None
it 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.CANCELLED
will be returned.New in version 2.22.
- accept_async(cancellable, callback, *user_data)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – 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.SocketConnection
on success,None
on error.- source_object:
Optional
GObject.Object
identifying this source
- Return type:
(
Gio.SocketConnection
, source_object:GObject.Object
orNone
)
Finishes an async accept operation. See
Gio.SocketListener.accept_async
()New in version 2.22.
- accept_socket(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore.- Raises:
- Returns:
a
Gio.Socket
on success,None
on error.- source_object:
location where
GObject.Object
pointer will be stored, orNone
.
- Return type:
(
Gio.Socket
, source_object:GObject.Object
orNone
)
Blocks waiting for a client to connect to any of the sockets added to the listener. Returns the
Gio.Socket
that 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
None
it 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.CANCELLED
will be returned.New in version 2.22.
- accept_socket_async(cancellable, callback, *user_data)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – 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.Socket
on success,None
on error.- source_object:
Optional
GObject.Object
identifying this source
- Return type:
(
Gio.Socket
, source_object:GObject.Object
orNone
)
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.SocketAddress
type (
Gio.SocketType
) – aGio.SocketType
protocol (
Gio.SocketProtocol
) – aGio.SocketProtocol
source_object (
GObject.Object
orNone
) – OptionalGObject.Object
identifying this source
- Raises:
- Returns:
True
on success,False
on 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-
None
then 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.Object
orNone
) – OptionalGObject.Object
identifying 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.Object
orNone
) – OptionalGObject.Object
identifying 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.Socket
source_object (
GObject.Object
orNone
) – OptionalGObject.Object
identifying 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.Socket
the 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.