Class DefaultServerConnection

java.lang.Object
com.realtime.crossfire.jxclient.server.server.DefaultServerConnection
All Implemented Interfaces:
ServerConnection

public class DefaultServerConnection extends Object implements ServerConnection
One of the two most important classes, ServerConnection performs most of the network-related work. It either decodes commands sent by the server itself, or delegates their processing to other classes, like Map or Faces.
  • Constructor Details

    • DefaultServerConnection

      public DefaultServerConnection(@NotNull @NotNull GuiStateManager guiStateManager, @Nullable @Nullable DebugWriter debugProtocol) throws IOException
      Creates a new instance.
      Parameters:
      guiStateManager - the gui state manager to update
      debugProtocol - tf non-null, write all protocol commands to this writer
      Throws:
      IOException - if an internal error occurs
  • Method Details

    • start

      public void start()
      Starts operation.
    • stop

      public void stop() throws InterruptedException
      Stops operation.
      Throws:
      InterruptedException - if stopping was interrupted
    • addClientSocketListener

      public void addClientSocketListener(@NotNull @NotNull ClientSocketListener clientSocketListener)
      Description copied from interface: ServerConnection
      Adds a ClientSocketListener to notify.
      Specified by:
      addClientSocketListener in interface ServerConnection
      Parameters:
      clientSocketListener - the client socket listener to add
    • removeClientSocketListener

      public void removeClientSocketListener(@NotNull @NotNull ClientSocketListener clientSocketListener)
      Description copied from interface: ServerConnection
      Removes a ClientSocketListener to notify.
      Specified by:
      removeClientSocketListener in interface ServerConnection
      Parameters:
      clientSocketListener - the client socket listener to remove
    • writePacket

      public void writePacket(byte @NotNull [] packet, int length, @NotNull @NotNull ClientSocketMonitorCommand monitor)
      Writes a Crossfire Message on the socket, so it is sent to the server.
      Parameters:
      packet - the packet to be sent; it does not include the length bytes but only actual payload data
      length - the length of packet; if the array is larger, excess data is ignored
      monitor - the monitor command to send to script processes
    • connect

      public void connect(@NotNull @NotNull String hostname, int port)
      Description copied from interface: ServerConnection
      Attempts to connect the client to a server.
      Specified by:
      connect in interface ServerConnection
      Parameters:
      hostname - the hostname to connect to
      port - the port to connect to
    • disconnect

      public void disconnect(@NotNull @NotNull String reason)
      Description copied from interface: ServerConnection
      Disconnects from the server. Does nothing if not connected.
      Specified by:
      disconnect in interface ServerConnection
      Parameters:
      reason - the reason for the disconnect