CSCI 380 Project 1:  The Random Number of the Day
Due Date:  4 March 23:59 handin name p1
  1. Random Number Server
  2. Write a program that generates a random value each day.  It should store this value in a file, along with the date, so that it can determine when it is started if it needs to generate a new value or use a value it has already generated.

    The program should create a connection on a server socket which will listen on a port and implements the following protocol based on the command received when a conection is made to the server:
    Any command other than one of these three may be either ignored or responded to with the random value of the day.

    The following code is a main method for a program that loops forever, listening on port 1337, reading in a line from a client that connects, and then simply echoing back the command.  You can use this code as a very basic framework from which to build your program.

     public static void main(String argv[]) throws Exception
        {
            String clientSentence;
            ServerSocket welcomeSocket = new ServerSocket (1337);

            while(true)
            {
                Socket connectionSocket = welcomeSocket.accept();
                BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
                System.out.println("Connection made");
                clientSentence = inFromClient.readLine();
                outToClient.writeBytes(clientSentence); // echo back
                outToClient.close();
            }
        }
    (If you'd like a possible ordering to the tasks here, I suggest first adding methods that generate a list of random values, and a permutation of values in a range.  Then I would add a method that keeps track of a random number for each day (in my implementation I use a file to hold date information and the random value) -- it's easiest to test this by thinking of it as a random number for each minute or hour.  I found the GregorianCalendar  class useful in my implementation.  Finally, once each of those pieces works, then I would worry about handling the clientSentence and writing values back to a client.)

  3. Web page interface to the server
  4. Provide a web page that uses XMLHTTP to provide a web interface to your server.  You will need a webpage with java and a php file on cerebro to make this interface work (just like our example in class).  

  5. What you'll hand in
You will provide your java code and a link to your webpage implementing the javascript (which will lead me to the php file).  You should also hand in an explanation of how you tested your solution, including known bugs.