Class Server

java.lang.Object
ucar.unidata.collab.Server
Direct Known Subclasses:
CollabServer

public class Server extends Object
A generic server
Author:
Metapps development team
  • Field Details

    • DEFAULT_PORT

      public static int DEFAULT_PORT
      _more_
  • Constructor Details

    • Server

      public Server()
      Create a new Server connection.
    • Server

      public Server(int port)
      Create a new Server connection on the given port.
      Parameters:
      port - the port
  • Method Details

    • startServer

      public void startServer(int newPort) throws IOException
      Start server.
      Parameters:
      newPort - the new port
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • startServer

      public void startServer() throws IOException
      Start server.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • stopServer

      public void stopServer()
      Stop server.
    • notifyServerStart

      protected void notifyServerStart()
      Gets called when we are starting to listen
    • notifyServerStop

      protected void notifyServerStop()
      Gets called when we are done running on the server socket
    • notifyClientAdd

      protected void notifyClientAdd(Client client)
      Gets called when we have added a new client.
      Parameters:
      client - the client
    • notifyClientRemove

      protected void notifyClientRemove(Client client)
      Gets called when we have removed a client.
      Parameters:
      client - the client
    • getIsRunning

      public boolean getIsRunning()
      Get the IsRunning property.
      Returns:
      The IsRunning
    • createClient

      protected Client createClient(Socket clientSocket) throws IOException
      A factory method for creating a new client.
      Parameters:
      clientSocket - The socket we are connected to the client with.
      Returns:
      a new Client
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • initClient

      protected void initClient(Socket clientSocket)
      Create a new client object and listen for input.
      Parameters:
      clientSocket - the client socket
    • getClients

      public List getClients()
      Gets the clients.
      Returns:
      the clients
    • hasClients

      public boolean hasClients()
      Does this server have any clients.
      Returns:
      true, if successful
    • addClient

      public void addClient(Client client)
      Add the given client to the list of clients managed by this server.
      Parameters:
      client - the client
    • addClient

      public void addClient(Client client, boolean andStartListening)
      Add the given client to the list of clients managed by this server.
      Parameters:
      client - the client
      andStartListening - the and start listening
    • removeClient

      public void removeClient(Client client)
      Remove the given client from the list of clients managed by this server.
      Parameters:
      client - the client
    • handleIncomingMessage

      protected void handleIncomingMessage(Client fromClient, String message)
      Handle the message rcvd from the given client. The default is to just turn around and write it to each of the other clients.
      Parameters:
      fromClient - the from client
      message - the message
    • write

      public void write(String message)
      Write.
      Parameters:
      message - the message
    • write

      public void write(String message, Client exceptClient)
      Write.
      Parameters:
      message - the message
      exceptClient - the except client
    • logException

      protected void logException(String msg, Exception exc)
      Log exception.
      Parameters:
      msg - the msg
      exc - the exc
    • main

      public static void main(String[] args)
      The main method.
      Parameters:
      args - the arguments