类 WebSocketClient

java.lang.Object
net.apexes.wsonrpc.client.support.websocket.WebSocketClient

public class WebSocketClient extends Object
  • 构造器详细资料

    • WebSocketClient

      public WebSocketClient(URI url)
      Create a websocket to connect to a given server
      参数:
      url - The URL of a websocket server
    • WebSocketClient

      public WebSocketClient(URI url, String protocol)
      Create a websocket to connect to a given server. Include protocol in websocket handshake
      参数:
      url - The URL of a websocket server
      protocol - The protocol to include in the handshake. If null, it will be omitted
    • WebSocketClient

      public WebSocketClient(URI url, String protocol, Map<String,String> extraHeaders)
      Create a websocket to connect to a given server. Include the given protocol in the handshake, as well as any extra HTTP headers specified. Useful if you would like to include a User-Agent or other header
      参数:
      url - The URL of a websocket server
      protocol - The protocol to include in the handshake. If null, it will be omitted
      extraHeaders - Any extra HTTP headers to be included with the initial request. Pass null if not extra headers are requested
  • 方法详细资料

    • setThreadFactory

      public static void setThreadFactory(ThreadFactory threadFactory, ThreadInitializer intializer)
    • setSocketFactory

      public void setSocketFactory(SocketFactory socketFactory)
    • setHostnameVerifier

      public void setHostnameVerifier(HostnameVerifier hostNameVerifier)
    • setEventHandler

      public void setEventHandler(WebSocketEventHandler eventHandler)
      Must be called before connect(). Set the support for all websocket-related events.
      参数:
      eventHandler - The support to be triggered with relevant events
    • getEventHandler

      public WebSocketEventHandler getEventHandler()
    • getState

      public WebSocketClient.State getState()
    • connect

      public void connect(int connectTimeout, int soTimeout)
      Start up the socket. This is non-blocking, it will fire up the threads used by the library and then trigger the onOpen support once the connection is established.
    • send

      public void send(String data)
      Send a TEXT message over the socket
      参数:
      data - The text payload to be sent
    • send

      public void send(byte[] data)
      Send a BINARY message over the socket
      参数:
      data - The binary payload to be sent
    • ping

      public void ping(byte[] bytes)
    • onPong

      protected void onPong(byte[] payload)
    • close

      public void close()
      Close down the socket. Will trigger the onClose support if the socket has not been previously closed.
    • blockClose

      public void blockClose() throws InterruptedException
      Blocks until both threads exit. The actual close must be triggered separately. This is just a convenience method to make sure everything shuts down, if desired.
      抛出:
      InterruptedException