Class ClientSocket

java.lang.Object
com.realtime.crossfire.jxclient.server.socket.ClientSocket

public class ClientSocket extends Object
A socket that processes incoming data.
 final ClientSocket clientSocket = new ClientSocket(...);
 clientSocket.writePacket(...);
 clientSocket.disconnect();
 
  • Constructor Details

    • ClientSocket

      public ClientSocket(@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 the socket cannot be created
  • 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)
      Adds a ClientSocketListener to be notified.
      Parameters:
      clientSocketListener - the client socket listener to add
    • removeClientSocketListener

      public void removeClientSocketListener(@NotNull @NotNull ClientSocketListener clientSocketListener)
      Removes a ClientSocketListener to be notified.
      Parameters:
      clientSocketListener - the client socket listener to remove
    • connect

      public void connect(@NotNull @NotNull String host, int port)
      Connects to a server. Disconnects an existing connection if necessary.
      Parameters:
      host - the host to connect to
      port - the port to connect to
    • disconnect

      public void disconnect(@NotNull @NotNull String reason, boolean isError)
      Terminates the connection. Does nothing if not connected.
      Parameters:
      reason - the reason for the disconnect
      isError - whether the disconnect is unexpected
    • writePacket

      public void writePacket(byte @NotNull [] buf, int len, @NotNull @NotNull ClientSocketMonitorCommand monitor)
      Writes a packet. The packet contents must not change until this function has returned.

      This function may be called even if the socket has been closed. In this case he packet is discarded.

      Parameters:
      buf - the packet to send
      len - the number of bytes to send
      monitor - the monitor command to send to script processes