Klasse SocketConnection

Alle implementierten Schnittstellen:
PointerInterface
Bekannte direkte Unterklassen:
TcpConnection, UnixConnection

public class SocketConnection extends IOStream
`GSocketConnection` is a [class@Gio.IOStream] for a connected socket. They
can be created either by [class@Gio.SocketClient] when connecting to a host,
or by [class@Gio.SocketListener] 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 [class@Gio.TcpConnection].

Choosing what type of object to construct is done with the socket
connection factory, and it is possible for third parties to register
custom socket connection types for specific combination of socket
family/type/protocol using [func@Gio.SocketConnection.factory_register_type].

To close a `GSocketConnection`, use [method@Gio.IOStream.close]. Closing both
substreams of the [class@Gio.IOStream] separately will not close the
underlying [class@Gio.Socket].

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

  • Konstruktordetails

  • Methodendetails

    • getClassHandler

      public static ClassHandler getClassHandler()
    • connect

      public boolean connect(@Nonnull SocketAddress address, @Nullable Cancellable cancellable) throws AllocationError
      Connect @connection to the specified remote address.
      Parameter:
      address - a #GSocketAddress specifying the remote address.
      cancellable - a %GCancellable or %NULL
      Gibt zurück:
      %TRUE if the connection succeeded, %FALSE on error
      Löst aus:
      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.

      If #GSocket:timeout is set, the operation will time out and return
      %G_IO_ERROR_TIMED_OUT after that period. Otherwise, it will continue
      indefinitely until operating system timeouts (if any) are hit.

      Use g_socket_connection_connect_finish() to retrieve the result.
      Parameter:
      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.
      Parameter:
      result - the #GAsyncResult
      Gibt zurück:
      %TRUE if the connection succeeded, %FALSE on error
      Löst aus:
      AllocationError
    • getLocalAddress

      public SocketAddress getLocalAddress() throws AllocationError
      Try to get the local address of a socket connection.
      Gibt zurück:
      a #GSocketAddress or %NULL on error. Free the returned object with g_object_unref().
      Löst aus:
      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)...".
      Gibt zurück:
      a #GSocketAddress or %NULL on error. Free the returned object with g_object_unref().
      Löst aus:
      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.
      Gibt zurück:
      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.
      Gibt zurück:
      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.
      Parameter:
      family - a #GSocketFamily
      type - a #GSocketType
      protocol_id - a protocol id
      Gibt zurück:
      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.
      Parameter:
      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()