Class RealWebSocket

java.lang.Object
org.miaixz.bus.http.socket.RealWebSocket
All Implemented Interfaces:
WebSocket, WebSocketReader.FrameCallback

public class RealWebSocket extends Object implements WebSocket, WebSocketReader.FrameCallback
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

  • Method Details

    • request

      public Request request()
      Specified by:
      request in interface WebSocket
      Returns:
      返回初始化此web套接字的请求
    • queueSize

      public long queueSize()
      Specified by:
      queueSize in interface WebSocket
      Returns:
      所有排队等待发送到服务器的消息的大小(以字节为单位)。这还不包括帧开销 它也不包括任何由操作系统或网络中介体缓冲的字节。如果队列中没有消息等待,则此方法返回0 如果在web套接字被取消后可能返回一个非零值;这表示未传输排队消息
    • cancel

      public void cancel()
      Description copied from interface: WebSocket
      立即并强烈地释放这个web套接字持有的资源,丢弃任何排队的消息 如果web套接字已经关闭或取消,则此操作不执行任何操作
      Specified by:
      cancel in interface WebSocket
    • connect

      public void connect(Httpd client)
    • initReaderAndWriter

      public void initReaderAndWriter(String name, RealWebSocket.Streams streams)
    • loopReader

      public void loopReader() throws IOException
      Receive frames until there are no more. Invoked only by the reader thread.
      Throws:
      IOException
    • onReadMessage

      public void onReadMessage(String text)
      Specified by:
      onReadMessage in interface WebSocketReader.FrameCallback
    • onReadMessage

      public void onReadMessage(org.miaixz.bus.core.io.ByteString bytes)
      Specified by:
      onReadMessage in interface WebSocketReader.FrameCallback
    • onReadPing

      public void onReadPing(org.miaixz.bus.core.io.ByteString payload)
      Specified by:
      onReadPing in interface WebSocketReader.FrameCallback
    • onReadPong

      public void onReadPong(org.miaixz.bus.core.io.ByteString buffer)
      Specified by:
      onReadPong in interface WebSocketReader.FrameCallback
    • onReadClose

      public void onReadClose(int code, String reason)
      Specified by:
      onReadClose in interface WebSocketReader.FrameCallback
    • send

      public boolean send(String text)
      Description copied from interface: WebSocket
      尝试将text编码为UTF-8并将其作为文本(类型为0x1)消息的数据发送 如果消息被加入队列,此方法将返回true。将溢出传出消息缓冲区的消息将被拒绝, 并触发此web套接字的graceful shutdown。此方法在这种情况下返回false, 在此web套接字关闭、关闭或取消的任何其他情况下也返回false
      Specified by:
      send in interface WebSocket
      Parameters:
      text - 文本信息
      Returns:
      the true/false
    • send

      public boolean send(org.miaixz.bus.core.io.ByteString bytes)
      Description copied from interface: WebSocket
      尝试将bytes作为二进制(类型为0x2)消息的数据发送 如果消息被加入队列,此方法将返回true。将溢出传出消息缓冲区(16 MiB)的消息将被拒绝, 并触发此web套接字的graceful shutdown。此方法在这种情况下返回false, 在此web套接字关闭、关闭或取消的任何其他情况下也返回false
      Specified by:
      send in interface WebSocket
      Parameters:
      bytes - 缓存流
      Returns:
      the true/false
    • close

      public boolean close(int code, String reason)
      Description copied from interface: WebSocket
      尝试启动此web套接字的正常关闭。任何已加入队列的消息将在发送关闭消息之前发送, 但是随后对WebSocket.send(java.lang.String)的调用将返回false,它们的消息将不被加入队列
      Specified by:
      close in interface WebSocket
      Parameters:
      code - RFC 6455第7.4节定义的状态码
      reason - 关闭或null的原因
      Returns:
      the true/false
    • failWebSocket

      public void failWebSocket(Exception e, Response response)