Package ch.bailu.gtk.gio
Class SocketListener
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gio.SocketListener
- All Implemented Interfaces:
PointerInterface
- Direct Known Subclasses:
SocketService
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 g_socket_listener_add_address()
and g_socket_listener_add_inet_port(). These will be listened on until
g_socket_listener_close() is called. Dropping your final reference to the
#GSocketListener will not cause g_socket_listener_close() to be called
implicitly, as some references to the #GSocketListener may be held
internally.
If you want to implement a network server, also look at #GSocketService
and #GThreadedSocketService which are subclasses of #GSocketListener
that make this even easier.
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 g_socket_listener_add_address()
and g_socket_listener_add_inet_port(). These will be listened on until
g_socket_listener_close() is called. Dropping your final reference to the
#GSocketListener will not cause g_socket_listener_close() to be called
implicitly, as some references to the #GSocketListener may be held
internally.
If you want to implement a network server, also look at #GSocketService
and #GThreadedSocketService which are subclasses of #GSocketListener
that make this even easier.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionCreates a new #GSocketListener with no sockets to listen for.SocketListener
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptAsync
(Cancellable cancellable, SocketListener.OnAsyncReadyCallback callback, Pointer user_data) This is the asynchronous version of g_socket_listener_accept().void
acceptSocketAsync
(Cancellable cancellable, SocketListener.OnAsyncReadyCallback callback, Pointer user_data) This is the asynchronous version of g_socket_listener_accept_socket().int
addAnyInetPort
(Object source_object) Listens for TCP connections on any available port number for both
IPv6 and IPv4 (if each is available).boolean
addInetPort
(int port, Object source_object) Helper function for g_socket_listener_add_address() that
creates a TCP/IP socket listening on IPv4 and IPv6 (if
supported) on the specified port on all interfaces.boolean
Adds @socket to the set of sockets that we try to accept
new clients from.void
close()
Closes all the sockets in the listener.static ClassHandler
static int
static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
onEvent
(SocketListener.OnEvent signal) Connect to signal "event".void
setBacklog
(int listen_backlog) Sets the listen backlog on the sockets in the listener.Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_EVENT
- See Also:
-
-
Constructor Details
-
SocketListener
-
SocketListener
public SocketListener()Creates a new #GSocketListener with no sockets to listen for.
New listeners can be added with e.g. g_socket_listener_add_address()
or g_socket_listener_add_inet_port().
-
-
Method Details
-
getClassHandler
-
acceptAsync
public void acceptAsync(@Nullable Cancellable cancellable, SocketListener.OnAsyncReadyCallback callback, @Nullable Pointer user_data) This is the asynchronous version of g_socket_listener_accept().
When the operation is finished @callback will be
called. You can then call g_socket_listener_accept_finish()
to get the result of the operation.- Parameters:
cancellable
- a #GCancellable, or %NULLcallback
- a #GAsyncReadyCallbackuser_data
- user data for the callback
-
acceptSocketAsync
public void acceptSocketAsync(@Nullable Cancellable cancellable, SocketListener.OnAsyncReadyCallback callback, @Nullable Pointer user_data) This is the asynchronous version of g_socket_listener_accept_socket().
When the operation is finished @callback will be
called. You can then call g_socket_listener_accept_socket_finish()
to get the result of the operation.- Parameters:
cancellable
- a #GCancellable, or %NULLcallback
- a #GAsyncReadyCallbackuser_data
- user data for the callback
-
addAnyInetPort
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.- Parameters:
source_object
- Optional #GObject identifying this source- Returns:
- the port number, or 0 in case of failure.
- Throws:
AllocationError
-
addInetPort
Helper function for g_socket_listener_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 g_socket_listener_close() to stop listening on @port; this will not
be done automatically when you drop your final reference to @listener, as
references may be held internally.- Parameters:
port
- an IP port number (non-zero)source_object
- Optional #GObject identifying this source- Returns:
- %TRUE on success, %FALSE on error.
- Throws:
AllocationError
-
addSocket
public boolean addSocket(@Nonnull Socket socket, @Nullable Object source_object) throws AllocationError 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 @listener 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 @listener, even
if references to it were held elsewhere.- Parameters:
socket
- a listening #GSocketsource_object
- Optional #GObject identifying this source- Returns:
- %TRUE on success, %FALSE on error.
- Throws:
AllocationError
-
close
public void close()Closes all the sockets in the listener. -
setBacklog
public void setBacklog(int listen_backlog) Sets the listen backlog on the sockets in the listener. This must be called
before adding any sockets, addresses or ports to the #GSocketListener (for
example, by calling g_socket_listener_add_inet_port()) to be effective.
See g_socket_set_listen_backlog() for details- Parameters:
listen_backlog
- an integer
-
onEvent
Connect to signal "event".
SeeSocketListener.OnEvent.onEvent(int, ch.bailu.gtk.gio.Socket)
for signal description.
FieldSIGNAL_ON_EVENT
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-