Subversion Repositories programming

Rev

Rev 223 | Go to most recent revision | 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
 *
10
 * Purpose: //FIXME
11
 ******************************************************************************/
12
 
222 ira 13
import java.net.*;
14
import java.io.*;
15
 
16
public class P3_Server
17
{
224 ira 18
    /* Instance Variables */
222 ira 19
    private static final int portNumber = 1337;
20
 
224 ira 21
    /**
22
     * Method: main
23
     * Purpose: Run the server. Accept connections on port 1337, and hand them
24
     * off to a new thread.
25
     */
222 ira 26
    public static void main (String[] args) throws IOException
27
    {
28
        ServerSocket socket = null;
29
        DHCPTable table = new DHCPTable ();
30
        boolean listening = true;
31
 
224 ira 32
        // Start the listening socket
222 ira 33
        try
34
        {
35
            socket = new ServerSocket (portNumber);
36
        }
37
        catch (IOException e)
38
        {
39
            System.err.println ("Could not listen on port: " + portNumber);
40
            System.exit (1);
41
        }
42
 
224 ira 43
        // Tell the user that we are successfully listening
223 ira 44
        System.out.println ("Listening for connections on port: " + portNumber);
224 ira 45
 
46
        // Every time a new connection comes in, accept it, spawn a new thread
47
        // to handle it, and keep listening.
222 ira 48
        while (listening)
49
            new P3_ServerThread (socket.accept(), table).start();
50
 
224 ira 51
        // Clean up the socket
222 ira 52
        socket.close();
53
    }
54
}
55