Package dev.adlin.vts4j.network
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
ConstructorsConstructorDescriptionSocketClient(@NonNull URI serverUri) Constructs a newSocketClientwith the specified remote server URI. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidvoidonOpen(org.java_websocket.handshake.ServerHandshake handshake) voidsetCloseHandler(@NonNull Consumer<CloseReason> onClose) Sets the handler to be called when the WebSocket connection terminates.voidsetErrorHandler(@NonNull Consumer<Exception> onError) Sets the handler to be called when an unhandled exception or protocol error occurs.voidsetMessageHandler(@NonNull Consumer<String> messageHandler) Sets the handler to be called when a raw string message frame is received from the WebSocket.voidsetOpenHandler(@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, setSocketFactoryMethods inherited from class org.java_websocket.AbstractWebSocket
getConnectionLostTimeout, isReuseAddr, isTcpNoDelay, setConnectionLostTimeout, setReuseAddr, setTcpNoDelay, startConnectionLostTimer, stopConnectionLostTimerMethods inherited from class org.java_websocket.WebSocketAdapter
onPreparePing, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeReceivedAsServer, onWebsocketHandshakeSentAsClient, onWebsocketPing, onWebsocketPong
-
Constructor Details
-
SocketClient
Constructs a newSocketClientwith the specified remote server URI.- Parameters:
serverUri- the rawURIof the destination WebSocket server
-
-
Method Details
-
onOpen
public void onOpen(org.java_websocket.handshake.ServerHandshake handshake) - Specified by:
onOpenin classorg.java_websocket.client.WebSocketClient
-
onMessage
- Specified by:
onMessagein classorg.java_websocket.client.WebSocketClient
-
onClose
- Specified by:
onClosein classorg.java_websocket.client.WebSocketClient
-
onError
- Specified by:
onErrorin classorg.java_websocket.client.WebSocketClient
-
setOpenHandler
Sets the handler to be called when the WebSocket connection is opened.- Parameters:
onOpen- the handler to be called on connection open, receives aServerHandshakeobject
-
setMessageHandler
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
Sets the handler to be called when the WebSocket connection terminates.- Parameters:
onClose- the handler to be called on connection close, receives aCloseReasonobject
-
setErrorHandler
Sets the handler to be called when an unhandled exception or protocol error occurs.- Parameters:
onError- the handler to be called on error, receives anExceptionobject
-