Rev 224 | 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: Listen on TCP Port 1337 for connections from the P3_Client. When a* valid request is recieved, it will give out the lowest ip address in it's* range.******************************************************************************/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 sockettry{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 listeningSystem.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 socketsocket.close();}}