Class MyServer

java.lang.Object
model.logic.server.MyServer
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
HostServer

public class MyServer extends Object implements Serializable
See Also:
  • Field Details

    • port

      protected final int port
    • clientHandler

      protected final ClientHandler clientHandler
    • stop

      protected volatile boolean stop
  • Constructor Details

    • MyServer

      public MyServer(int port, ClientHandler clientHandler)
      Constructor for MyServer class. Initializes the server with specified port number and client handler.
      Parameters:
      port - the port number to use for the server
      clientHandler - the client handler to use for handling client connections
  • Method Details

    • start

      public void start()
      Starts the server in a new thread.
      Throws:
      RuntimeException - if an error occurs while starting the server.
    • close

      public void close()
      Closes the server and stops accepting new connections. Also, closes the client handler.
    • runServer

      protected void runServer() throws Exception
      Starts the server and listens for incoming client connections. Once a connection is established, the client handler is called to handle the client's input/output streams. The method runs in a loop until the server is stopped.
      Throws:
      Exception - if there is an error while creating or closing the server socket