Class SocketConnection

All Implemented Interfaces:
PointerInterface
Direct Known Subclasses:
TcpConnection, UnixConnection

public class SocketConnection extends IOStream
#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.

https://docs.gtk.org/gio/class.SocketConnection.html

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler 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 %NULL
      callback - a #GAsyncReadyCallback
      user_data - user data for the callback
    • connectFinish

      public boolean connectFinish(@Nonnull AsyncResult result) throws AllocationError
      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

      public SocketAddress getLocalAddress() throws AllocationError
      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

      public SocketAddress getRemoteAddress() throws AllocationError
      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

      public Socket 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 #GSocketFamily
      type - a #GSocketType
      protocol_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_CONNECTION
      family - a #GSocketFamily
      type - a #GSocketType
      protocol - a protocol id
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()