Module bus.http

Class WebSocketListener

java.lang.Object
org.miaixz.bus.http.socket.WebSocketListener
Direct Known Subclasses:
CoverCall.Listener

public abstract class WebSocketListener extends Object
A listener for events related to a WebSocket connection.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onClosed(WebSocket webSocket, int code, String reason)
    Invoked when both peers have indicated that no more messages will be transmitted and the connection has been successfully released.
    void
    onClosing(WebSocket webSocket, int code, String reason)
    Invoked when the remote peer has indicated that no more incoming messages will be transmitted.
    void
    onFailure(WebSocket webSocket, Throwable throwable, Response response)
    Invoked when a web socket has been closed due to an error reading from or writing to the network.
    void
    onMessage(WebSocket webSocket, String text)
    Invoked when a text (type 0x1) message has been received.
    void
    onMessage(WebSocket webSocket, org.miaixz.bus.core.io.ByteString bytes)
    Invoked when a binary (type 0x2) message has been received.
    void
    onOpen(WebSocket webSocket, Response response)
    Invoked when a web socket has been accepted by the remote peer and may begin transmitting messages.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WebSocketListener

      public WebSocketListener()
  • Method Details

    • onOpen

      public void onOpen(WebSocket webSocket, Response response)
      Invoked when a web socket has been accepted by the remote peer and may begin transmitting messages.
      Parameters:
      webSocket - The WebSocket that has been opened.
      response - The HTTP response from the upgrade request.
    • onMessage

      public void onMessage(WebSocket webSocket, String text)
      Invoked when a text (type 0x1) message has been received.
      Parameters:
      webSocket - The WebSocket that received the message.
      text - The text content of the message.
    • onMessage

      public void onMessage(WebSocket webSocket, org.miaixz.bus.core.io.ByteString bytes)
      Invoked when a binary (type 0x2) message has been received.
      Parameters:
      webSocket - The WebSocket that received the message.
      bytes - The binary content of the message.
    • onClosing

      public void onClosing(WebSocket webSocket, int code, String reason)
      Invoked when the remote peer has indicated that no more incoming messages will be transmitted.
      Parameters:
      webSocket - The WebSocket that is closing.
      code - The status code from the remote peer.
      reason - The reason for the closure, or an empty string.
    • onClosed

      public void onClosed(WebSocket webSocket, int code, String reason)
      Invoked when both peers have indicated that no more messages will be transmitted and the connection has been successfully released. No further calls to this listener will be made.
      Parameters:
      webSocket - The WebSocket that has been closed.
      code - The status code from the remote peer.
      reason - The reason for the closure, or an empty string.
    • onFailure

      public void onFailure(WebSocket webSocket, Throwable throwable, Response response)
      Invoked when a web socket has been closed due to an error reading from or writing to the network. Both outgoing and incoming messages may have been lost. No further calls to this listener will be made.
      Parameters:
      webSocket - The WebSocket that failed.
      throwable - The exception that caused the failure.
      response - The HTTP response from the upgrade request, or null if no response was received.