Added sendfile and loggin through webserver
authoradash <adash>
Sat, 28 Oct 2006 01:34:40 +0000 (01:34 +0000)
committeradash <adash>
Sat, 28 Oct 2006 01:34:40 +0000 (01:34 +0000)
Robust/src/Tests/WebServerExample.java
Robust/src/Tests/WebServerSocket.java

index d4f14009698b95d165bd2d69d8c412080503c714..471ce6a35f6233a26ad2d96fac2f6e0b337b348a 100644 (file)
@@ -21,9 +21,11 @@ task AcceptConnection(ServerSocket ss{SocketPending}) {
 
 /* Send a Write Request to Client*/
 task WriteIO(WebServerSocket web{WritePending}) {
-       System.printString("W> Before doing WriteIO 0\n");
+       System.printString("W> Before sending response\n");
        web.httpresponse();
-       System.printString("W> After doing WriteIO\n");
+       System.printString("W> After sending response\n");
+       web.sendfile();
+       System.printString("W> After sending file\n");
        web.close();
        taskexit(web {!WritePending});  
 }
index 716cdcf9aa03419571452d2e78a85040441eee0b..90ff4dff3c743d785535d9562c5e642c4bb11c38 100644 (file)
@@ -2,12 +2,11 @@ public class WebServerSocket extends Socket {
        // Websocket flag
        flag ReadPending;
        flag WritePending;
-       //File Descriptor
-       int fd;
-
+       
        //Constructor
        public WebServerSocket(){
-
+               Logger log = new Logger();
+               log.logrequest();               
        }
        
        public void datawrite(){ 
@@ -24,30 +23,38 @@ public class WebServerSocket extends Socket {
                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("Content-length: 88");
                header.append("\n\n");
-               
-
-               htmlBuffer.append("<HEAD>\n<TITLE>Test HTML Document</TITLE>\n");
-               htmlBuffer.append(" </HEAD>\n");
-               htmlBuffer.append("          \n");
-               htmlBuffer.append("   <BODY>\n");
-               htmlBuffer.append("   <h1>This is your java web server's default page.</h1>");
-               htmlBuffer.append("   </BODY>\n");
-               htmlBuffer.append("</HTML>\n"); 
-       
-               header.append(htmlBuffer.toString());
-               
                String temp_str = new String(header);
                write(temp_str.getBytes());
                return;
+
+       }
+       
+       //Send the html file , read from file one byte at a time        
+       public void sendfile() {
+               String filepath = new String("./Tests/htmlfiles/index2.html");
+               FileInputStream def_file = new FileInputStream(filepath);
+               byte buf[] = new byte[16];
+               int ret;
+               
+               while ((ret = def_file.read(buf)) > 0) {
+                       byte tosend[] = new byte[ret];
+                       for (int i = 0; i < ret; i++) {
+                               tosend[i] = buf[i];
+                       }
+                       write(tosend);
+                       String str = new String(tosend);
+               }
+               def_file.close();
        }
+
+
 }