// Melvin K Lew <melvin@columbia.edu>
// $Source: /amd/cheers-fast/root/np/melvin/AIS/aisproj/RCS/WBServer.java,v $
// $Date: 1998/04/27 00:44:30 $
// $Author: melvin $
// $Revision: 1.9 $
//
// CS-E6998-03 Advanced Internet Services: Term Project
//
// The JINCS Project: Collaborative Whiteboard Client/Server Application
//
// Group:
//	Johan Andersen <johan@columbia.edu>
//	Richard Denmark <thor@columbia.edu>
//	Melvin Lew <melvin@columbia.edu
//
// A multi-threaded networked Whiteboard Server
//

import java.io.*;
import java.net.*;
import java.util.*;
import WBSListenThread.*;

/**
 * Contains main method for the Whiteboard server and starts up
 * the server listen thread.
 *
 * @author	Melvin K Lew
 * @version	$Revision: 1.9 $, $Date: 1998/04/27 00:44:30 $
 *
 * @see		WBSListenThread
 */
public class WBServer
{
  private static Hashtable clienthash = new Hashtable();
  private static int port = 1998;
  public static boolean debug = false;

  /**
   * Class constructor.
   *
   * @param	clienthash	a hashtable containing client information
   * @param	port		an integer for user specified port number
   */
  public WBServer(Hashtable clienthash, int port) {
    this.clienthash = clienthash;
    this.port = port;
  }
    
  /**
   * main for the Whiteboard server, spawns server listen thread.
   *
   * @param	args		a string array of command line arguments
   * @exception	IOException	If an IO error occurred
   *
   * @see	WBSListenThread
   */
  public static void main(String[] args) throws IOException
  {
    String str;

    // if this property is defined as true, we run in debug mode
    str = System.getProperty("WBServer-debug");
    if ( str != null ) {
      debug = str.equalsIgnoreCase("true");
    }

    // the user may specify a different port to use
    if ( args.length > 0 ) {
      port = Integer.parseInt(args[0]);
    }
    // let the user know the server has started
    System.out.println("### Starting WBServer on " +
		       InetAddress.getLocalHost().getHostName() + "/" +
		       port + "\n###");

    // spawn a thread to listen for new connections on the port
    new WBSListenThread(clienthash, port).start();
      
  }
}
