Package Model

Class ClientCommunication

java.lang.Object
java.util.Observable
Model.ClientCommunication

public class ClientCommunication extends Observable
This class is responsible for the communication between the client and the server It sends messages to the server and notifies the observers when a message is received The protocol is: id:method:input1,input2,... The id is the id of the client, -1 means that the client is not connected yet
  • Constructor Details

    • ClientCommunication

      public ClientCommunication()
    • ClientCommunication

      public ClientCommunication(String ip, int port, String name)
      Creates a new client communication with the server and starts a new thread to check for messages from the server
      Parameters:
      ip - the host to connect to
      port - the port to connect to
  • Method Details

    • connect

      public void connect(String ip, int port, String name)
    • send

      public void send(int id, String methodName, String... args)
      Sends a message to the server, protocol: id:method:input1,input2,...
      Parameters:
      id - the id of the client
      methodName - the method name to call
      args - the inputs to the method
    • close

      public void close()
      close the socket connection to the server -> stop the thread