Package ch.bailu.gtk.gio
Class SocketConnection
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gio.IOStream
ch.bailu.gtk.gio.SocketConnection
- All Implemented Interfaces:
PointerInterface
- Direct Known Subclasses:
TcpConnection
,UnixConnection
#GSocketConnection is a #GIOStream for a connected socket. They
can be created either by #GSocketClient when connecting to a host,
or by #GSocketListener 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 #GTcpConnection.
Choosing what type of object to construct is done with the socket
connection factory, and it is possible for 3rd parties to register
custom socket connection types for specific combination of socket
family/type/protocol using g_socket_connection_factory_register_type().
To close a #GSocketConnection, use g_io_stream_close(). Closing both
substreams of the #GIOStream separately will not close the underlying
#GSocket.
can be created either by #GSocketClient when connecting to a host,
or by #GSocketListener 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 #GTcpConnection.
Choosing what type of object to construct is done with the socket
connection factory, and it is possible for 3rd parties to register
custom socket connection types for specific combination of socket
family/type/protocol using g_socket_connection_factory_register_type().
To close a #GSocketConnection, use g_io_stream_close(). Closing both
substreams of the #GIOStream separately will not close the underlying
#GSocket.
-
Nested Class Summary
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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
connect
(SocketAddress address, Cancellable cancellable) Connect @connection to the specified remote address.void
connectAsync
(SocketAddress address, Cancellable cancellable, SocketConnection.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously connect @connection to the specified remote address.boolean
connectFinish
(AsyncResult result) Gets the result of a g_socket_connection_connect_async() call.static long
factoryLookupType
(int family, int type, int protocol_id) Looks up the #GType to be used when creating socket connections on
sockets with the specified @family, @type and @protocol_id.static void
factoryRegisterType
(long g_type, int family, int type, int protocol) Looks up the #GType to be used when creating socket connections on
sockets with the specified @family, @type and @protocol.static ClassHandler
static int
Try to get the local address of a socket connection.static long
static TypeSystem.TypeSize
Try to get the remote address of a socket connection.Gets the underlying #GSocket object of the connection.static long
static TypeSystem.TypeSize
boolean
Checks if @connection is connected.Methods inherited from class ch.bailu.gtk.gio.IOStream
clearPending, close, closeAsync, closeFinish, getInputStream, getOutputStream, hasPending, isClosed, setPending, spliceAsync, spliceFinish
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
-
Constructor Details
-
SocketConnection
-
-
Method Details
-
getClassHandler
-
connect
public boolean connect(@Nonnull SocketAddress address, @Nullable Cancellable cancellable) throws AllocationError Connect @connection to the specified remote address.- Parameters:
address
- a #GSocketAddress specifying the remote address.cancellable
- a %GCancellable or %NULL- Returns:
- %TRUE if the connection succeeded, %FALSE on error
- Throws:
AllocationError
-
connectAsync
public void connectAsync(@Nonnull SocketAddress address, @Nullable Cancellable cancellable, SocketConnection.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously connect @connection to the specified remote address.
This clears the #GSocket:blocking flag on @connection's underlying
socket if it is currently set.
Use g_socket_connection_connect_finish() to retrieve the result.- Parameters:
address
- a #GSocketAddress specifying the remote address.cancellable
- a %GCancellable or %NULLcallback
- a #GAsyncReadyCallbackuser_data
- user data for the callback
-
connectFinish
Gets the result of a g_socket_connection_connect_async() call.- Parameters:
result
- the #GAsyncResult- Returns:
- %TRUE if the connection succeeded, %FALSE on error
- Throws:
AllocationError
-
getLocalAddress
Try to get the local address of a socket connection.- Returns:
- a #GSocketAddress or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
getRemoteAddress
Try to get the remote address of a socket connection.
Since GLib 2.40, when used with g_socket_client_connect() or
g_socket_client_connect_async(), during emission of
%G_SOCKET_CLIENT_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)...".- Returns:
- a #GSocketAddress or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
getSocket
Gets the underlying #GSocket object of the connection.
This can be useful if you want to do something unusual on it
not supported by the #GSocketConnection APIs.- Returns:
- a #GSocket or %NULL on error.
-
isConnected
public boolean isConnected()Checks if @connection is connected. This is equivalent to calling
g_socket_is_connected() on @connection's underlying #GSocket.- Returns:
- whether @connection is connected
-
factoryLookupType
public static long factoryLookupType(int family, int type, int protocol_id) Looks up the #GType to be used when creating socket connections on
sockets with the specified @family, @type and @protocol_id.
If no type is registered, the #GSocketConnection base type is returned.- Parameters:
family
- a #GSocketFamilytype
- a #GSocketTypeprotocol_id
- a protocol id- Returns:
- a #GType
-
factoryRegisterType
public static void factoryRegisterType(long g_type, int family, int type, int protocol) Looks up the #GType to be used when creating socket connections on
sockets with the specified @family, @type and @protocol.
If no type is registered, the #GSocketConnection base type is returned.- Parameters:
g_type
- a #GType, inheriting from %G_TYPE_SOCKET_CONNECTIONfamily
- a #GSocketFamilytype
- a #GSocketTypeprotocol
- a protocol id
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-