Module bus.http

Interface WebSocket

All Known Implementing Classes:
RealWebSocket

public interface WebSocket
A non-blocking interface to a WebSocket. In normal operation, a WebSocket will be processed through a sequence of states: open, message, and close. Use a WebSocket.Factory (typically the Httpd client) to create instances.
Since:
Java 17+
Author:
Kimi Liu
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    A factory for creating WebSockets.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Immediately and violently release resources held by this web socket, discarding any enqueued messages.
    boolean
    close(int code, String reason)
    Attempts to initiate a graceful shutdown of this web socket.
    long
    Returns the number of bytes of application data that have been enqueued to be transmitted to the server.
     
    boolean
    send(String text)
    Attempts to enqueue text to be transmitted as a text (type 0x1) message.
    boolean
    send(org.miaixz.bus.core.io.ByteString bytes)
    Attempts to enqueue bytes to be transmitted as a binary (type 0x2) message.
  • Method Details

    • request

      Request request()
      Returns:
      The original request that initiated this WebSocket.
    • queueSize

      long queueSize()
      Returns the number of bytes of application data that have been enqueued to be transmitted to the server. This doesn't include framing overhead. It also doesn't include any bytes that have been buffered by the operating system or network intermediaries. This method returns 0 if no messages are waiting in the queue. It may return a non-zero value after the web socket has been canceled; this indicates that enqueued messages were not transmitted.
      Returns:
      The size of the outgoing message queue in bytes.
    • send

      boolean send(String text)
      Attempts to enqueue text to be transmitted as a text (type 0x1) message.

      This method returns true if the message was enqueued. Messages that would overflow the outgoing message buffer will be rejected and trigger a graceful shutdown of this web socket. This method returns false in that case, and in any other case where this web socket is closing, closed, or canceled.

      Parameters:
      text - The text message to send.
      Returns:
      true if the message was successfully enqueued for sending.
    • send

      boolean send(org.miaixz.bus.core.io.ByteString bytes)
      Attempts to enqueue bytes to be transmitted as a binary (type 0x2) message.

      This method returns true if the message was enqueued. Messages that would overflow the outgoing message buffer (16 MiB) will be rejected and trigger a graceful shutdown of this web socket. This method returns false in that case, and in any other case where this web socket is closing, closed, or canceled.

      Parameters:
      bytes - The binary message to send.
      Returns:
      true if the message was successfully enqueued for sending.
    • close

      boolean close(int code, String reason)
      Attempts to initiate a graceful shutdown of this web socket. Any already-enqueued messages will be transmitted before the close message is sent but subsequent calls to send(java.lang.String) will return false and their messages will not be enqueued.
      Parameters:
      code - A status code as defined by Section 7.4 of RFC 6455.
      reason - A descriptive reason for the close, or null.
      Returns:
      true if the close message was successfully enqueued.
      Throws:
      IllegalArgumentException - if the code is invalid.
    • cancel

      void cancel()
      Immediately and violently release resources held by this web socket, discarding any enqueued messages. This does nothing if the web socket has already been closed or canceled.