Subversion Repositories programming

Rev

Rev 223 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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