Package client
Class ClientWebSocketHandler
java.lang.Object
org.java_websocket.WebSocketAdapter
org.java_websocket.AbstractWebSocket
org.java_websocket.client.WebSocketClient
client.ClientWebSocketHandler
- All Implemented Interfaces:
Runnable,org.java_websocket.WebSocket,org.java_websocket.WebSocketListener
public class ClientWebSocketHandler
extends org.java_websocket.client.WebSocketClient
-
Field Summary
Fields inherited from class org.java_websocket.client.WebSocketClient
uriFields inherited from class org.java_websocket.AbstractWebSocket
DEFAULT_READ_BUFFER_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionClientWebSocketHandler(URI serverUri) Constructor for ClientWebSocketHandler. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(WebSocketEventListener listener) Adds a WebSocketEventListener to the list of listeners.voidSends a message to the server to enter a specific chat room.voidSends a login message to the server with the provided username.voidNotifies listeners of disconnection when the WebSocket connection is closed.voidNotifies listeners of any errors that occur in the WebSocket connection.voidHandles incoming messages from the WebSocket connection.voidonOpen(org.java_websocket.handshake.ServerHandshake handshakedata) Handles start of connection WebSocket server.voidremoveListener(WebSocketEventListener listener) Removes a WebSocketEventListener from the list of listeners.voidsendMessageToServer(Message message, String chatName) Sends a message to the server within a specific chat.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, getReceiveBufferSize, isDaemon, isReuseAddr, isTcpNoDelay, setConnectionLostTimeout, setDaemon, setReceiveBufferSize, setReuseAddr, setTcpNoDelay, startConnectionLostTimer, stopConnectionLostTimerMethods inherited from class org.java_websocket.WebSocketAdapter
onPreparePing, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeReceivedAsServer, onWebsocketHandshakeSentAsClient, onWebsocketPing, onWebsocketPong
-
Constructor Details
-
ClientWebSocketHandler
Constructor for ClientWebSocketHandler. Initializes the WebSocket client with the provided server URI.- Parameters:
serverUri- The URI of the WebSocket server.
-
-
Method Details
-
onOpen
public void onOpen(org.java_websocket.handshake.ServerHandshake handshakedata) Handles start of connection WebSocket server. Notifies listeners.- Specified by:
onOpenin classorg.java_websocket.client.WebSocketClient- Parameters:
handshakedata- The ServerHandshake object containing handshake data from the server.
-
onMessage
Handles incoming messages from the WebSocket connection. Parses the message and notifies listeners.- Specified by:
onMessagein classorg.java_websocket.client.WebSocketClient- Parameters:
message- The raw message received from the WebSocket connection.
-
enterChat
Sends a message to the server to enter a specific chat room.- Parameters:
chatName- The name of the chat room to enter.
-
login
Sends a login message to the server with the provided username.- Parameters:
username- The username to be sent to the server for login.
-
sendMessageToServer
Sends a message to the server within a specific chat.- Parameters:
message- The Message object to be sent.chatName- The name of the chat to send the message to.
-
onClose
Notifies listeners of disconnection when the WebSocket connection is closed.- Specified by:
onClosein classorg.java_websocket.client.WebSocketClient- Parameters:
code- The status code representing the reason for closure.reason- A string describing the reason for closure.remote- A boolean indicating whether the closure was initiated by the remote host.
-
onError
Notifies listeners of any errors that occur in the WebSocket connection.- Specified by:
onErrorin classorg.java_websocket.client.WebSocketClient- Parameters:
ex- The Exception object representing the error that occurred.
-
addListener
Adds a WebSocketEventListener to the list of listeners.- Parameters:
listener- The WebSocketEventListener to be added to the array of listeners.
-
removeListener
Removes a WebSocketEventListener from the list of listeners.- Parameters:
listener- The WebSocketEventListener to be removed from the array of listeners.
-