Testing version
authoradash <adash>
Wed, 1 Nov 2006 07:08:05 +0000 (07:08 +0000)
committeradash <adash>
Wed, 1 Nov 2006 07:08:05 +0000 (07:08 +0000)
Robust/src/Tests/WebServerExample.java
Robust/src/Tests/WebServerSocket.java

index 471ce6a35f6233a26ad2d96fac2f6e0b337b348a..8e3ab2184a8d86fba36383613151fbead1ba536f 100644 (file)
@@ -1,32 +1,46 @@
 /* Startup object is generated with the initialstate flag set by the
  *  system to start the computation up */
 
-
 /* Create New ServerSocket*/
-
 task Startup(StartupObject s {initialstate}) {
        System.printString("W> Starting\n");
-       ServerSocket ss=new ServerSocket(9000);
+       ServerSocket ss = new ServerSocket(9000);
        System.printString("W> Creating ServerSocket\n");
+       Logger log = new Logger() {LogPending};
        taskexit(s {!initialstate}); /* Turns initial state flag off, so this task won't refire */
 }
 
 /*Listen for a request and accept request*/ 
 task AcceptConnection(ServerSocket ss{SocketPending}) {
        System.printString("W> Waiting for connection...\n");
-       WebServerSocket web = new WebServerSocket() {WritePending};
+       WebServerSocket web = new WebServerSocket() {!WritePending};
        ss.accept(web);
        System.printString("W> Connected... \n");
 }
 
-/* Send a Write Request to Client*/
-task WriteIO(WebServerSocket web{WritePending}) {
-       System.printString("W> Before sending response\n");
-       web.httpresponse();
-       System.printString("W> After sending response\n");
-       web.sendfile();
-       System.printString("W> After sending file\n");
-       web.close();
-       taskexit(web {!WritePending});  
+/* Process the incoming http request */
+task ProcessRequest(WebServerSocket web{IOPending}) {
+       System.printString("W> Inside ProcessRequest... \n");
+       //web.clientrequest();
+       web.debug_read();
+       taskexit(web {WritePending});
+}
+
+task testWritePending(WebServerSocket web{WritePending}) {
+       System.printString("W> Testing WritePending");
+       //taskexit(web {!WritePending, testflag});
+       taskexit(web {!WritePending});
 }
 
+task testflag(WebServerSocket web{testflag}) {
+       System.printString("DEBUG -> Test flag is true");
+       taskexit(web {!testflag});
+}
+
+/*
+task LogRequest(Logger log{LogPending}) {
+       log.logrequest();
+       System.printString("L> Inside logrequest");
+       taskexit(log {!LogPending});
+}
+*/
index 90ff4dff3c743d785535d9562c5e642c4bb11c38..3cf36df908ee0d60de3f7a1a44f614ac2fad1490 100644 (file)
@@ -2,32 +2,17 @@ public class WebServerSocket extends Socket {
        // Websocket flag
        flag ReadPending;
        flag WritePending;
+       flag testflag;
+       boolean parsed;
        
        //Constructor
        public WebServerSocket(){
-               Logger log = new Logger();
-               log.logrequest();               
+               parsed = false;
        }
        
-       public void datawrite(){ 
-               byte[] b = new byte[10];
-               b[0] =(byte)'H';
-               b[1] =(byte)'E';
-               b[2] =(byte)'L';
-               b[3] =(byte)'L';
-               b[4] =(byte)'O';
-       //      b[5] =(byte)'\n';
-               b[6] =(byte)'T';
-               b[7] =(byte)'E';
-               b[8] =(byte)'S';
-               b[9] =(byte)'T';
-               write(b);
-       }
-
        //Send the http header for web browser display  
        public void httpresponse(){
                StringBuffer header = new StringBuffer("HTTP/1.0 200 OK\n");
-               StringBuffer htmlBuffer = new StringBuffer("<HTML>\n");
 
                header.append("Content-type: text/html\n");
                header.append("\n\n");
@@ -38,9 +23,22 @@ public class WebServerSocket extends Socket {
        }
        
        //Send the html file , read from file one byte at a time        
-       public void sendfile() {
-               String filepath = new String("./Tests/htmlfiles/index2.html");
+       public void sendfile(String filename) {
+               //String filepath = new String("./Tests/htmlfiles/index1.html");
+               StringBuffer req_file = new StringBuffer("./Tests/htmlfiles/");
+               req_file.append(filename);
+               String filepath = new String(req_file);
                FileInputStream def_file = new FileInputStream(filepath);
+               int status = def_file.getfd();  
+               if (status == -1){
+                       StringBuffer response = new StringBuffer("404: not found: ");
+                       response.append(filename);
+                       String buffer = new String(response);
+                       write(buffer.getBytes());
+                       //System.printString("File does not  exist");
+                       def_file.close();
+                       return;
+               }
                byte buf[] = new byte[16];
                int ret;
                
@@ -55,6 +53,44 @@ public class WebServerSocket extends Socket {
                def_file.close();
        }
 
+       //Discover what the client wants and handle their request       
+       public int clientrequest(){
+               byte b1[] = new byte[1024];
+               while(read(b1)<0);
+               //String clientreq = new String(b1);
+               //System.printString(clientreq);
+               //int index = clientreq.indexOf('/');
+               //int end = clientreq.indexOf('H');
+               //String filename = clientreq.subString((index+1), (end-1));
+               System.printString("DEBUG -> Inside clientreq ");
+               //System.printString(filename);
+               return 0;
+       }
+               
+       public int debug_read() {
+               byte b1[] = new byte[1024];
+               while(read(b1)<0);
+               String dummy = new String(b1);
+               System.printString(dummy);
+               return 0;
+       }
+
+       public int checkrequest(){
+               byte b1[] = new byte[1024];
+               boolean found = false;
+
+               while(read(b1) < 0);
+               String clientreq = new String(b1);
+               int length = clientreq.length();
+               System.printString(clientreq);
+               
+       }       
+       //Send response if html file requested not available
+       public void htmlresponse(String filename){
+               String s = new String(filename);
+               
+
+       }
 
 }