Module bus.http

Class CoverCall.Client

java.lang.Object
org.miaixz.bus.http.plugin.httpv.CoverHttp<CoverCall.Client>
org.miaixz.bus.http.plugin.httpv.CoverCall.Client
All Implemented Interfaces:
Cancelable
Enclosing class:
CoverCall

public static class CoverCall.Client extends CoverHttp<CoverCall.Client>
A client for creating and configuring WebSocket connections.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • Client

      public Client(Httpv client, String url)
      Constructs a new WebSocket client.
      Parameters:
      client - The HTTP client instance.
      url - The WebSocket URL.
  • Method Details

    • heatbeat

      public CoverCall.Client heatbeat(int pingSeconds, int pongSeconds)
      Sets the heartbeat interval, overriding the default heartbeat mode.

      Key differences: 1. Any message sent by the client acts as a heartbeat. 2. Any message sent by the server acts as a heartbeat. 3. A timeout is only triggered if the server does not reply within 3 * pongSeconds. 4. The specific content of the heartbeat can be specified (defaults to empty).

      Parameters:
      pingSeconds - The client's heartbeat interval in seconds (0 means no heartbeat).
      pongSeconds - The server's heartbeat interval in seconds (0 means no heartbeat).
      Returns:
      this client instance for chaining.
    • listen

      public CoverCall listen()
      Starts the WebSocket connection and returns a CoverCall to interact with it.
      Returns:
      The CoverCall representing the connection.
    • setOnOpen

      public CoverCall.Client setOnOpen(CoverCall.Register<CoverResult> onOpen)
      Sets the open connection listener.
      Parameters:
      onOpen - The listener.
      Returns:
      this client instance for chaining.
    • setOnException

      public CoverCall.Client setOnException(CoverCall.Register<Throwable> onException)
      Sets the connection exception listener.
      Parameters:
      onException - The listener.
      Returns:
      this client instance for chaining.
    • setOnMessage

      public CoverCall.Client setOnMessage(CoverCall.Register<CoverCall.Message> onMessage)
      Sets the message listener.
      Parameters:
      onMessage - The listener.
      Returns:
      this client instance for chaining.
    • setOnClosing

      public CoverCall.Client setOnClosing(CoverCall.Register<CoverCall.Close> onClosing)
      Sets the closing listener.
      Parameters:
      onClosing - The listener.
      Returns:
      this client instance for chaining.
    • setOnClosed

      public CoverCall.Client setOnClosed(CoverCall.Register<CoverCall.Close> onClosed)
      Sets the closed listener (also called on cancellation or exception).
      Parameters:
      onClosed - The listener.
      Returns:
      this client instance for chaining.
    • pingSeconds

      public int pingSeconds()
      Returns:
      The configured client-to-server ping interval in seconds.
    • pongSeconds

      public int pongSeconds()
      Returns:
      The configured expected server-to-client pong interval in seconds.