Subversion Repositories programming

Rev

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

Rev 188 Rev 189
Line 14... Line 14...
14
import java.io.*;
14
import java.io.*;
15
import java.net.*;
15
import java.net.*;
16
 
16
 
17
public class P1Server
17
public class P1Server
18
{
18
{
-
 
19
    /* Instance variables */
19
    public static final int portNumber = 1337;
20
    public static final int portNumber = 1337;
20
    public static final String exitSeq = "QUIT";
21
    public static final String exitSeq = "QUIT";
21
 
22
 
22
    /**
23
    /**
23
     * Method: main()
24
     * Method: main
24
     * Purpose: This method creates a listening socket on port 1337 and
25
     * Purpose: This method creates a listening socket on port 1337 and
25
     * accepts the first connection made to it. It then echoes back anything
26
     * accepts the first connection made to it. It then echoes back anything
26
     * sent to it, until it recieves a "QUIT", at which point it terminates.
27
     * sent to it, until it recieves a "QUIT", at which point it terminates.
27
     */
28
     */
28
    public static void main (String[] args) throws IOException
29
    public static void main (String[] args) throws IOException
Line 63... Line 64...
63
        String inputLine, outputLine;
64
        String inputLine, outputLine;
64
 
65
 
65
        /* Read input and echo back to output */
66
        /* Read input and echo back to output */
66
        while ((inputLine = in.readLine()) != null)
67
        while ((inputLine = in.readLine()) != null)
67
        {
68
        {
-
 
69
            /* Echo back what we recieved */
-
 
70
            out.println (inputLine);
-
 
71
 
68
            /* If we recieve a message to quit, do so. */
72
            /* If we recieve a message to quit, do so. */
69
            if (inputLine.equals (exitSeq))
73
            if (inputLine.equals (exitSeq))
70
                break;
74
                break;
71
            
-
 
72
            /* Echo back what we recieved */
-
 
73
            out.println (inputLine);
-
 
74
        }
75
        }
75
 
76
 
76
        /* Cleanup */
77
        /* Cleanup */
77
        out.close();
78
        out.close();
78
        in.close();
79
        in.close();