Package dev.adlin.vts4j.network
Class NetworkClient
java.lang.Object
dev.adlin.vts4j.network.NetworkClient
High-level network client that delegates infrastructure operations to an underlying socket client.
Implements both asynchronous and synchronous (blocking) connection lifecycle management methods, alongside payload dispatching and custom event hook registrations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidEstablishes a synchronous connection to the remote server, blocking the calling thread indefinitely until the handshake completes or fails.voidawaitConnect(long timeout, @NonNull TimeUnit timeUnit) Establishes a synchronous connection to the remote server, blocking the calling thread up to the specified timeout interval.voidSynchronously tears down the active socket session, blocking the calling thread until the close handshake is acknowledged.voidconnect()Initiates a non-blocking background connection routine to the remote server.voidInitiates an asynchronous non-blocking disconnection routine.voidTransmits a raw string payload over the active socket session.voidsetCloseHandler(@NonNull Consumer<CloseReason> closeReason) Assigns a callback hook triggered immediately after the socket session terminates.voidsetErrorHandler(@NonNull Consumer<Exception> handler) Assigns a custom error monitoring callback hook.voidsetMessageHandler(@NonNull Consumer<String> handleMessage) Assigns the main core callback interceptor for incoming data packets.voidsetOpenHandler(@NonNull Consumer<org.java_websocket.handshake.ServerHandshake> handshake) Assigns a callback hook triggered upon successful completion of the opening handshake.
-
Constructor Details
-
NetworkClient
-
-
Method Details
-
awaitConnect
public void awaitConnect()Establishes a synchronous connection to the remote server, blocking the calling thread indefinitely until the handshake completes or fails.- Throws:
RuntimeException- if the thread is interrupted while waiting to connect
-
awaitConnect
Establishes a synchronous connection to the remote server, blocking the calling thread up to the specified timeout interval.- Parameters:
timeout- the maximum duration to wait for a connectiontimeUnit- the time unit of the timeout argument- Throws:
RuntimeException- if the thread is interrupted while waiting to connect
-
connect
public void connect()Initiates a non-blocking background connection routine to the remote server. -
awaitDisconnect
public void awaitDisconnect()Synchronously tears down the active socket session, blocking the calling thread until the close handshake is acknowledged.- Throws:
RuntimeException- if the thread is interrupted while executing the close procedure
-
disconnect
public void disconnect()Initiates an asynchronous non-blocking disconnection routine. -
send
Transmits a raw string payload over the active socket session.- Parameters:
payload- the message payload string to send to the server
-
setMessageHandler
Assigns the main core callback interceptor for incoming data packets.- Parameters:
handleMessage- functional consumer handling inbound raw strings
-
setErrorHandler
Assigns a custom error monitoring callback hook.- Parameters:
handler- functional consumer handling raw network or protocol exceptions
-
setOpenHandler
public void setOpenHandler(@NonNull Consumer<org.java_websocket.handshake.ServerHandshake> handshake) Assigns a callback hook triggered upon successful completion of the opening handshake.- Parameters:
handshake- functional consumer processing handshake details
-
setCloseHandler
Assigns a callback hook triggered immediately after the socket session terminates.- Parameters:
closeReason- functional consumer analyzing closure state parameters
-