Class WSClient

java.lang.Object
com.gmt2001.wsclient.WSClient

public final class WSClient extends Object
Provides a WebSocket client
Author:
gmt2001
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor that does not initialize a WSPinger
    WSClient(URI uri, WsClientFrameHandler handler, WSPinger pinger)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves the socket channel
    void
    Sends a WebSocket frame of type Close with a status code of NORMAL_CLOSURE, then closes the socket, with a grace period for ongoing requests to finish
    void
    close(int status, String reason)
    Sends a WebSocket frame of type Close, then closes the socket, with a grace period for ongoing requests to finish
    void
    Sends a WebSocket frame of type Close, then closes the socket, with a grace period for ongoing requests to finish
    void
    Sends a WebSocket frame of type Close, then closes the socket, with a grace period for ongoing requests to finish
    void
    close(WebSocketFrame closeFrame)
    Sends a WebSocket frame of type Close, then closes the socket, with a grace period for ongoing requests to finish
    boolean
    Connects to the server
    boolean
    Indicates if the socket is connected.
    void
    send(byte[] binarydata)
    Sends a WebSocket frame of type Binary
    void
    Sends a WebSocket frame
    void
    send(String text)
    Sends a WebSocket frame of type Text
    void
    Stringifys a JSONObject, then sends it as a WebSocket frame of type Text

    Methods inherited from class java.lang.Object

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

  • Method Details

    • connect

      public boolean connect() throws InterruptedException, IllegalStateException
      Connects to the server
      Returns:
      true if the socket has connected and is starting the handshake; false otherwise
      Throws:
      InterruptedException - The connection process was interrupted
      IllegalStateException - Attempting to use a closed client
    • connected

      public boolean connected()
      Indicates if the socket is connected. NOTE: Only indicates that the socket is ready to send/receive frames. Does not indicate authentication status or anything else
      Returns:
      true if the socket is connected and ready to send/receive frames; false otherwise
    • channel

      public Channel channel()
      Retrieves the socket channel
      Returns:
      The socket channel if connected; null otherwise
    • send

      public void send(WebSocketFrame frame)
      Sends a WebSocket frame
      Parameters:
      frame - The frame to send
    • send

      public void send(String text)
      Sends a WebSocket frame of type Text
      Parameters:
      text - The body content of the frame
    • send

      public void send(JSONObject jso)
      Stringifys a JSONObject, then sends it as a WebSocket frame of type Text
      Parameters:
      jso - The JSONObject to send
    • send

      public void send(byte[] binarydata)
      Sends a WebSocket frame of type Binary
      Parameters:
      binarydata - The binary bytes to send
    • close

      public void close()
      Sends a WebSocket frame of type Close with a status code of NORMAL_CLOSURE, then closes the socket, with a grace period for ongoing requests to finish
    • close

      public void close(WebSocketCloseStatus status)
      Sends a WebSocket frame of type Close, then closes the socket, with a grace period for ongoing requests to finish
      Parameters:
      status - The close status code to send
    • close

      public void close(WebSocketCloseStatus status, String reason)
      Sends a WebSocket frame of type Close, then closes the socket, with a grace period for ongoing requests to finish
      Parameters:
      status - The close status code to send
      reason - The reason string to send
    • close

      public void close(int status, String reason)
      Sends a WebSocket frame of type Close, then closes the socket, with a grace period for ongoing requests to finish
      Parameters:
      status - The close status code to send
      reason - The reason string to send
    • close

      public void close(WebSocketFrame closeFrame)
      Sends a WebSocket frame of type Close, then closes the socket, with a grace period for ongoing requests to finish
      Parameters:
      closeFrame - The close frame to send