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

    uri

    Fields inherited from class org.java_websocket.AbstractWebSocket

    DEFAULT_READ_BUFFER_SIZE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for ClientWebSocketHandler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a WebSocketEventListener to the list of listeners.
    void
    enterChat(String chatName)
    Sends a message to the server to enter a specific chat room.
    void
    login(String username)
    Sends a login message to the server with the provided username.
    void
    onClose(int code, String reason, boolean remote)
    Notifies listeners of disconnection when the WebSocket connection is closed.
    void
    Notifies listeners of any errors that occur in the WebSocket connection.
    void
    onMessage(String message)
    Handles incoming messages from the WebSocket connection.
    void
    onOpen(org.java_websocket.handshake.ServerHandshake handshakedata)
    Handles start of connection WebSocket server.
    void
    Removes a WebSocketEventListener from the list of listeners.
    void
    sendMessageToServer(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, setSocketFactory

    Methods inherited from class org.java_websocket.AbstractWebSocket

    getConnectionLostTimeout, getReceiveBufferSize, isDaemon, isReuseAddr, isTcpNoDelay, setConnectionLostTimeout, setDaemon, setReceiveBufferSize, 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

    • ClientWebSocketHandler

      public ClientWebSocketHandler(URI serverUri)
      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:
      onOpen in class org.java_websocket.client.WebSocketClient
      Parameters:
      handshakedata - The ServerHandshake object containing handshake data from the server.
    • onMessage

      public void onMessage(String message)
      Handles incoming messages from the WebSocket connection. Parses the message and notifies listeners.
      Specified by:
      onMessage in class org.java_websocket.client.WebSocketClient
      Parameters:
      message - The raw message received from the WebSocket connection.
    • enterChat

      public void enterChat(String chatName)
      Sends a message to the server to enter a specific chat room.
      Parameters:
      chatName - The name of the chat room to enter.
    • login

      public void login(String username)
      Sends a login message to the server with the provided username.
      Parameters:
      username - The username to be sent to the server for login.
    • sendMessageToServer

      public void sendMessageToServer(Message message, String chatName)
      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

      public void onClose(int code, String reason, boolean remote)
      Notifies listeners of disconnection when the WebSocket connection is closed.
      Specified by:
      onClose in class org.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

      public void onError(Exception ex)
      Notifies listeners of any errors that occur in the WebSocket connection.
      Specified by:
      onError in class org.java_websocket.client.WebSocketClient
      Parameters:
      ex - The Exception object representing the error that occurred.
    • addListener

      public void addListener(WebSocketEventListener listener)
      Adds a WebSocketEventListener to the list of listeners.
      Parameters:
      listener - The WebSocketEventListener to be added to the array of listeners.
    • removeListener

      public void removeListener(WebSocketEventListener listener)
      Removes a WebSocketEventListener from the list of listeners.
      Parameters:
      listener - The WebSocketEventListener to be removed from the array of listeners.