Stable version 0.1 - Accepts multiple connections, TODO: Log
authoradash <adash>
Wed, 1 Nov 2006 08:05:29 +0000 (08:05 +0000)
committeradash <adash>
Wed, 1 Nov 2006 08:05:29 +0000 (08:05 +0000)
client request using flag combinations from different classes

Robust/src/Tests/Logger.java
Robust/src/Tests/WebServerExample.java
Robust/src/Tests/WebServerSocket.java

index 0603758e189e5463aaa56a5318fda73b264a370b..9e85f5bf5e63ce1373c3517e97f9dddc17d8619d 100644 (file)
@@ -1,18 +1,25 @@
 public class Logger extends FileOutputStream {
        //Logging flag
        flag LogPending;
-       
+
        //Constructor
        public Logger(){
+               FileOutputStreamOpen("./Tests/htmlfiles/request.log");
+       }
+
+       public void logrequest(String filename){
+               String request = new String("\nNew Request received: ");
+               write(request.getBytes());
+               write(filename.getBytes());
+               flush();
        }
 
        public void logrequest(){
-               String filepath = new String("./Tests/htmlfiles/request.log");
-               String request = new String(" New Request received\n");
-               int mode=0;
-               FileOutputStream logfile = new FileOutputStream(filepath,mode);
-               logfile.write(request.getBytes());
-               logfile.close();        
+               String request = new String("\nNew Request received: ");
+               flush();
        }
 
+       public void closerequest() {
+               close();        
+       }
 }
index 8e3ab2184a8d86fba36383613151fbead1ba536f..6d223a21a8cd93cc6eb9987a28340ebfb2cc97fe 100644 (file)
@@ -6,7 +6,7 @@ task Startup(StartupObject s {initialstate}) {
        System.printString("W> Starting\n");
        ServerSocket ss = new ServerSocket(9000);
        System.printString("W> Creating ServerSocket\n");
-       Logger log = new Logger() {LogPending};
+       Logger log = new Logger() {!LogPending};
        taskexit(s {!initialstate}); /* Turns initial state flag off, so this task won't refire */
 }
 
@@ -21,26 +21,17 @@ task AcceptConnection(ServerSocket ss{SocketPending}) {
 /* Process the incoming http request */
 task ProcessRequest(WebServerSocket web{IOPending}) {
        System.printString("W> Inside ProcessRequest... \n");
-       //web.clientrequest();
-       web.debug_read();
+       web.clientrequest();
        taskexit(web {WritePending});
 }
 
-task testWritePending(WebServerSocket web{WritePending}) {
-       System.printString("W> Testing WritePending");
-       //taskexit(web {!WritePending, testflag});
+task SendFile(WebServerSocket web{WritePending}) {
+       System.printString("W> Inside SendFile ... \n");
+       web.sendfile();
+       web.close();
        taskexit(web {!WritePending});
 }
 
-task testflag(WebServerSocket web{testflag}) {
-       System.printString("DEBUG -> Test flag is true");
-       taskexit(web {!testflag});
-}
-
-/*
-task LogRequest(Logger log{LogPending}) {
+task LogFile( Logger log {LogPending}){
        log.logrequest();
-       System.printString("L> Inside logrequest");
-       taskexit(log {!LogPending});
 }
-*/
index 3cf36df908ee0d60de3f7a1a44f614ac2fad1490..416ae280d46f24105cdbb9ea1ca7a01e148459f9 100644 (file)
@@ -2,18 +2,15 @@ public class WebServerSocket extends Socket {
        // Websocket flag
        flag ReadPending;
        flag WritePending;
-       flag testflag;
-       boolean parsed;
+       String filename;
        
        //Constructor
        public WebServerSocket(){
-               parsed = false;
        }
        
        //Send the http header for web browser display  
        public void httpresponse(){
                StringBuffer header = new StringBuffer("HTTP/1.0 200 OK\n");
-
                header.append("Content-type: text/html\n");
                header.append("\n\n");
                String temp_str = new String(header);
@@ -22,14 +19,15 @@ public class WebServerSocket extends Socket {
 
        }
        
-       //Send the html file , read from file one byte at a time        
-       public void sendfile(String filename) {
+       // Send the html file , read from file one byte at a time       
+       public void sendfile() {
                //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();  
+               httpresponse();
                if (status == -1){
                        StringBuffer response = new StringBuffer("404: not found: ");
                        response.append(filename);
@@ -56,41 +54,16 @@ public class WebServerSocket extends Socket {
        //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);
+               //while(read(b1)<0);
+               read(b1);
                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);
-               
-
+               int index = clientreq.indexOf('/');
+               int end = clientreq.indexOf('H');
+               filename = clientreq.subString((index+1), (end-1));
+               System.printString("DEBUG -> Client requested: ");
+               System.printString(filename);
+               System.printString("\n");
+               return 0;
        }
-
 }