Subversion Repositories programming

Rev

Rev 224 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
221 ira 1
/*******************************************************************************
2
 * File: P3_Server.java
3
 * Author: Ira W. Snyder (devel@irasnyder.com)
4
 * License: GNU General Public License v2
5
 * Class: CS380 - Computer Networking
6
 *
7
 * Assignment: Project #3
8
 * Date Last Modified: 2006-02-15
9
 *
260 ira 10
 * Purpose: Listen on TCP Port 1337 for connections from the P3_Client. When a
11
 * valid request is recieved, it will give out the lowest ip address in it's
12
 * range.
221 ira 13
 ******************************************************************************/
14
 
222 ira 15
import java.net.*;
16
import java.io.*;
17
 
18
public class P3_Server
19
{
224 ira 20
    /* Instance Variables */
222 ira 21
    private static final int portNumber = 1337;
22
 
224 ira 23
    /**
24
     * Method: main
25
     * Purpose: Run the server. Accept connections on port 1337, and hand them
26
     * off to a new thread.
27
     */
222 ira 28
    public static void main (String[] args) throws IOException
29
    {
30
        ServerSocket socket = null;
31
        DHCPTable table = new DHCPTable ();
32
        boolean listening = true;
33
 
224 ira 34
        // Start the listening socket
222 ira 35
        try
36
        {
37
            socket = new ServerSocket (portNumber);
38
        }
39
        catch (IOException e)
40
        {
41
            System.err.println ("Could not listen on port: " + portNumber);
42
            System.exit (1);
43
        }
44
 
224 ira 45
        // Tell the user that we are successfully listening
223 ira 46
        System.out.println ("Listening for connections on port: " + portNumber);
224 ira 47
 
48
        // Every time a new connection comes in, accept it, spawn a new thread
49
        // to handle it, and keep listening.
222 ira 50
        while (listening)
51
            new P3_ServerThread (socket.accept(), table).start();
52
 
224 ira 53
        // Clean up the socket
222 ira 54
        socket.close();
55
    }
56
}
57