harmmeijer
Programmer
I am trying to modify the following code:
URL:
applet:
Server:
In the server code I have changed all 1.0 to 1.1 and before the lines:
// Check if the command was valid
if (!str.endsWith(" HTTP/1.1") {
I put the following code segment:
System.out.println("got a string value " + str);
if(str.endsWith("/chat HTTP/1.1"){
System.out.println("found a match, now get the html code to the browser"
PrintStream outHTML = new PrintStream
(new BufferedOutputStream(s.getOutputStream()), true);
outHTML.println("<applet code=\"SimpleChatApplet.class\" width=350 height=225 alt=\"\"><param name=port value=80></applet>"
outHTML.println("\r"
outHTML.flush();
in.close();
s.close();
System.out.println("Code passed to the browser."
continue;
}
if(str.endsWith("/SimpleChatApplet.class HTTP/1.1"){
System.out.println("Now to pass the the applet to the Browser"
FileInputStream fleApplet = new FileInputStream(new File("C:\\j2sdk1.4.0_03\\bin\\chat\\SimpleChatApplet.class");
BufferedOutputStream outApplet = new BufferedOutputStream(s.getOutputStream());
int b = fleApplet.read();
while(b!=-1){
outApplet.write(b);
b = fleApplet.read();
}
System.out.println("End of the loop"
outApplet.flush();
System.out.println("flush"
fleApplet.close();
System.out.println("file close"
in.close();
System.out.println("in close"
s.close();
System.out.println("Applet passed to the browser."
continue;
}
Changed the port values to 80 so the server will serve as a web server.
Reason for this is that "burrowing through firewalls" is not realy burrowing through because all ports on the proxy are closed so using 6006 is not an option. Using the only available port (80) disables the web server since the chatserver and the webserver cannot both be using port 80 so the chatserver has to function as a web server.
The only thing it needs to do is pass the html code (works) and the pass the applet (gives an error client side):
(last 2 lines)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
So the client browser request "http:servername/chat", the chatserver "if(str.endsWith("/chat HTTP/1.1")" statement is true and the chatserver prints a view lines to the output stream.
These lines are html code telling the browser to create an applet then the java plugin takes over and the java plugin request "servername/SimpleChatApplet.class" the chatserver picks this up (statement "if(str.endsWith("/SimpleChatApplet.class HTTP/1.1")" is true), opens the class file on the server and passes this file in the output stream to the client. Then the java plugin requests the applet again, chatserver does the same. Finally the plugin gives up and generates the error or crashes.
I like this application because it shows how the server pushes an update to the client in a web application (using http). This is the only example I found where the client did not submit every couple of seconds to see if there is new information but the server tells the client when there is new information. Don't need a chat application I need this to run on port 80.
Can anybody help me with this?
Thanx
Greetings, Harm Meijer
URL:
applet:
Server:
In the server code I have changed all 1.0 to 1.1 and before the lines:
// Check if the command was valid
if (!str.endsWith(" HTTP/1.1") {
I put the following code segment:
System.out.println("got a string value " + str);
if(str.endsWith("/chat HTTP/1.1"){
System.out.println("found a match, now get the html code to the browser"
PrintStream outHTML = new PrintStream
(new BufferedOutputStream(s.getOutputStream()), true);
outHTML.println("<applet code=\"SimpleChatApplet.class\" width=350 height=225 alt=\"\"><param name=port value=80></applet>"
outHTML.println("\r"
outHTML.flush();
in.close();
s.close();
System.out.println("Code passed to the browser."
continue;
}
if(str.endsWith("/SimpleChatApplet.class HTTP/1.1"){
System.out.println("Now to pass the the applet to the Browser"
FileInputStream fleApplet = new FileInputStream(new File("C:\\j2sdk1.4.0_03\\bin\\chat\\SimpleChatApplet.class");
BufferedOutputStream outApplet = new BufferedOutputStream(s.getOutputStream());
int b = fleApplet.read();
while(b!=-1){
outApplet.write(b);
b = fleApplet.read();
}
System.out.println("End of the loop"
outApplet.flush();
System.out.println("flush"
fleApplet.close();
System.out.println("file close"
in.close();
System.out.println("in close"
s.close();
System.out.println("Applet passed to the browser."
continue;
}
Changed the port values to 80 so the server will serve as a web server.
Reason for this is that "burrowing through firewalls" is not realy burrowing through because all ports on the proxy are closed so using 6006 is not an option. Using the only available port (80) disables the web server since the chatserver and the webserver cannot both be using port 80 so the chatserver has to function as a web server.
The only thing it needs to do is pass the html code (works) and the pass the applet (gives an error client side):
(last 2 lines)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
So the client browser request "http:servername/chat", the chatserver "if(str.endsWith("/chat HTTP/1.1")" statement is true and the chatserver prints a view lines to the output stream.
These lines are html code telling the browser to create an applet then the java plugin takes over and the java plugin request "servername/SimpleChatApplet.class" the chatserver picks this up (statement "if(str.endsWith("/SimpleChatApplet.class HTTP/1.1")" is true), opens the class file on the server and passes this file in the output stream to the client. Then the java plugin requests the applet again, chatserver does the same. Finally the plugin gives up and generates the error or crashes.
I like this application because it shows how the server pushes an update to the client in a web application (using http). This is the only example I found where the client did not submit every couple of seconds to see if there is new information but the server tells the client when there is new information. Don't need a chat application I need this to run on port 80.
Can anybody help me with this?
Thanx
Greetings, Harm Meijer