Class ConnectionHandler


  • public class ConnectionHandler
    extends java.lang.Object
    Handles the connection with a game. Can be used to receive or send messages. Receiving messages works with registered Events.
    • Constructor Detail

      • ConnectionHandler

        public ConnectionHandler​(org.java_websocket.WebSocket ws)
        Creates a new ConnectionHandler, with an open and validated WebSocket
        Parameters:
        ws - open and valid WebSocket connection
    • Method Detail

      • listen

        public ConnectionHandler.EventRef listen​(Event.EventType event,
                                                 ConnectionHandler.EventCallback callback)
        Listen to an Event of the game. This method WILL NOT send an registration action. This action is intended to use for listening to events that are not requested. Use register if you are not sure this method is the right one.
        Parameters:
        event - event type to register
        callback - callback to call on event
        Returns:
        EventRef for unregistering
      • unregister

        public void unregister()
        Unregister all Events.
      • unregister

        public void unregister​(Event.EventType event)
        Unregister all callbacks of a specific event type.
        Parameters:
        event - EventRef returned while registering.
      • unregister

        public void unregister​(ConnectionHandler.EventRef ref)
        Unregister a specific Event.
        Parameters:
        ref - EventRef returned while registering.
      • send

        public void send​(ActionsList ac)
                  throws org.java_websocket.exceptions.WebsocketNotConnectedException
        Send actions to Game.
        Parameters:
        ac - action to send
        Throws:
        org.java_websocket.exceptions.WebsocketNotConnectedException - gets thrown when action limit is exceeded
      • send

        public void send​(Action ac)
                  throws org.java_websocket.exceptions.WebsocketNotConnectedException
        Send action to Game.
        Parameters:
        ac - action to send
        Throws:
        org.java_websocket.exceptions.WebsocketNotConnectedException - gets thrown when action limit is exceeded
      • receive

        public boolean receive​(Event msg)
        Message received from ws, for in game.
        Parameters:
        msg - pure String received
        Returns:
        if the game is still running
      • connectionClosed

        public void connectionClosed()
        Notifies the ConnectionHandler, that the Game connection was closed.