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