Subversion Repositories programming

Rev

Rev 223 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*******************************************************************************
 * File: P3_Server.java
 * Author: Ira W. Snyder (devel@irasnyder.com)
 * License: GNU General Public License v2
 * Class: CS380 - Computer Networking
 *
 * Assignment: Project #3
 * Date Last Modified: 2006-02-15
 *
 * Purpose: //FIXME
 ******************************************************************************/

import java.net.*;
import java.io.*;

public class P3_Server
{
    /* Instance Variables */
    private static final int portNumber = 1337;

    /**
     * Method: main
     * Purpose: Run the server. Accept connections on port 1337, and hand them
     * off to a new thread.
     */
    public static void main (String[] args) throws IOException
    {
        ServerSocket socket = null;
        DHCPTable table = new DHCPTable ();
        boolean listening = true;

        // Start the listening socket
        try
        {
            socket = new ServerSocket (portNumber);
        }
        catch (IOException e)
        {
            System.err.println ("Could not listen on port: " + portNumber);
            System.exit (1);
        }

        // Tell the user that we are successfully listening
        System.out.println ("Listening for connections on port: " + portNumber);

        // Every time a new connection comes in, accept it, spawn a new thread
        // to handle it, and keep listening.
        while (listening)
            new P3_ServerThread (socket.accept(), table).start();

        // Clean up the socket
        socket.close();
    }
}