Class SocketClient

java.lang.Object
org.java_websocket.WebSocketAdapter
org.java_websocket.AbstractWebSocket
org.java_websocket.client.WebSocketClient
dev.adlin.vts4j.network.SocketClient
All Implemented Interfaces:
Runnable, org.java_websocket.WebSocket, org.java_websocket.WebSocketListener

public class SocketClient extends org.java_websocket.client.WebSocketClient
Low-level WebSocket client implementation that bridges underlying socket events (open, message, close, error) to configurable functional consumers.
  • Field Summary

    Fields inherited from class org.java_websocket.client.WebSocketClient

    uri
  • Constructor Summary

    Constructors
    Constructor
    Description
    SocketClient(@NonNull URI serverUri)
    Constructs a new SocketClient with the specified remote server URI.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onClose(int code, String reason, boolean remote)
     
    void
    onError(Exception exception)
     
    void
    onMessage(String message)
     
    void
    onOpen(org.java_websocket.handshake.ServerHandshake handshake)
     
    void
    Sets the handler to be called when the WebSocket connection terminates.
    void
    setErrorHandler(@NonNull Consumer<Exception> onError)
    Sets the handler to be called when an unhandled exception or protocol error occurs.
    void
    setMessageHandler(@NonNull Consumer<String> messageHandler)
    Sets the handler to be called when a raw string message frame is received from the WebSocket.
    void
    setOpenHandler(@NonNull Consumer<org.java_websocket.handshake.ServerHandshake> onOpen)
    Sets the handler to be called when the WebSocket connection is opened.

    Methods inherited from class org.java_websocket.client.WebSocketClient

    addHeader, clearHeaders, close, close, close, closeBlocking, closeConnection, connect, connectBlocking, connectBlocking, getAttachment, getConnection, getConnections, getDraft, getLocalSocketAddress, getLocalSocketAddress, getProtocol, getReadyState, getRemoteSocketAddress, getRemoteSocketAddress, getResourceDescriptor, getSocket, getSSLSession, getURI, hasBufferedData, hasSSLSupport, isClosed, isClosing, isFlushAndClose, isOpen, onCloseInitiated, onClosing, onMessage, onSetSSLParameters, onWebsocketClose, onWebsocketCloseInitiated, onWebsocketClosing, onWebsocketError, onWebsocketMessage, onWebsocketMessage, onWebsocketOpen, onWriteDemand, reconnect, reconnectBlocking, removeHeader, run, send, send, send, sendFragmentedFrame, sendFrame, sendFrame, sendPing, setAttachment, setDnsResolver, setProxy, setSocket, setSocketFactory

    Methods inherited from class org.java_websocket.AbstractWebSocket

    getConnectionLostTimeout, isReuseAddr, isTcpNoDelay, setConnectionLostTimeout, setReuseAddr, setTcpNoDelay, startConnectionLostTimer, stopConnectionLostTimer

    Methods inherited from class org.java_websocket.WebSocketAdapter

    onPreparePing, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeReceivedAsServer, onWebsocketHandshakeSentAsClient, onWebsocketPing, onWebsocketPong

    Methods inherited from class java.lang.Object

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

    • SocketClient

      public SocketClient(@NonNull URI serverUri)
      Constructs a new SocketClient with the specified remote server URI.
      Parameters:
      serverUri - the raw URI of the destination WebSocket server
  • Method Details

    • onOpen

      public void onOpen(org.java_websocket.handshake.ServerHandshake handshake)
      Specified by:
      onOpen in class org.java_websocket.client.WebSocketClient
    • onMessage

      public void onMessage(String message)
      Specified by:
      onMessage in class org.java_websocket.client.WebSocketClient
    • onClose

      public void onClose(int code, String reason, boolean remote)
      Specified by:
      onClose in class org.java_websocket.client.WebSocketClient
    • onError

      public void onError(Exception exception)
      Specified by:
      onError in class org.java_websocket.client.WebSocketClient
    • setOpenHandler

      public void setOpenHandler(@NonNull Consumer<org.java_websocket.handshake.ServerHandshake> onOpen)
      Sets the handler to be called when the WebSocket connection is opened.
      Parameters:
      onOpen - the handler to be called on connection open, receives a ServerHandshake object
    • setMessageHandler

      public void setMessageHandler(@NonNull Consumer<String> messageHandler)
      Sets the handler to be called when a raw string message frame is received from the WebSocket.
      Parameters:
      messageHandler - the handler to be called on message receipt, receives the message payload as a String
    • setCloseHandler

      public void setCloseHandler(@NonNull Consumer<CloseReason> onClose)
      Sets the handler to be called when the WebSocket connection terminates.
      Parameters:
      onClose - the handler to be called on connection close, receives a CloseReason object
    • setErrorHandler

      public void setErrorHandler(@NonNull Consumer<Exception> onError)
      Sets the handler to be called when an unhandled exception or protocol error occurs.
      Parameters:
      onError - the handler to be called on error, receives an Exception object