Package test

Class MyServer

java.lang.Object
test.MyServer

public class MyServer extends Object
  • Constructor Details

    • MyServer

      public MyServer(int port, ClientHandler ch)
      The MyServer function is a constructor for the MyServer class. It initializes the port number, client handler and stop boolean to be used by the server. It also creates a thread pool of cached threads that will be used by the server to handle clients.
      Parameters:
      port - int -Set the port number that the server will listen to
      ch - ClientHandler -Handle the client's request
  • Method Details

    • start

      public void start()
      The start function starts the server in a new Thread.
    • close

      public void close() throws InterruptedException
      The close function is used to close the thread pool. It sets the stop variable to true, and then shuts down the thread pool and end the server by exiting the loop in the startServer function. If there are any threads that are still running, it will wait for them to finish before shutting down.
      Throws:
      InterruptedException