/* 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});
+}
+*/
// 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");
}
//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;
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);
+
+
+ }
}