[Prev][Next][Index][Thread]
Using JAVA applets from cl-http
I am having trouble using a JAVA applet (with cl-http 58.12, PowerPC MCL
3.9, MacOS 7.5.3 Update 2).
Problem 1: I exported the following file:
<HTML>
<HEAD>
<TITLE>Post testing for Hannah</TITLE>
</HEAD>
<BODY>
<P>
<APPLET CODE="PostHannah.class" WIDTH=500 HEIGHT=300>
</APPLET>
</BODY>
</HTML>
using the following form
(http:export-url #u"/c-recs/form.html"
:html-file
:pathname "Macintosh HD:Documents:Lisp
Code:C-ReCS:POSTHANNAH.HTML")
My client found the HTML file but not the class file, even when I gave the
absolute pathname for the JAVA class file in the HTML file. What am I doing
wrong? Note that if I loaded the HTML file as a file instead of accessing
it as an exported URL, my client DID find the class file.
Problem 2: Once the Java class file was loaded, the code tries to open a
socket to the cl-http server at port 80 in order to send it POSTs and GETs.
The Applet gave me the following error when trying to create the new
socket:
java.net.SocketException: unknown error (socket: Host: hannah.arl.psu.edu
Port: 80)
The applet did not produce that error when opening a socket to a Unix-based
http server.
I've included the source code for the Java applet below.
What am I doing wrong here? Your suggestions would be greatly appreciated.
Thanks,
Mark Klein
================
import java.applet.Applet;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class PostHannah extends Applet
{
private final String script = "/c-recs/test-java-apt.html";
private final String ctype ="application/x-www-form-urlencoded";
private String sdata = "Hello World";
private String rdata = "";
private String home;
private int port;
public void init()
{
home = "hannah.arl.psu.edu";
port = 80;
}
public void start()
{
Socket sock;
OutputStream outp;
InputStream inp;
DataOutputStream dataout;
DataInputStream datain;
rdata = "";
//create a client socket
try
sock = new Socket(home, port);
catch (Exception e)
{
rdata = e+" (socket: Host: "+home+"\tPort: "+port+")";
return;
}
// Obtain output stream to communicate with the server
try
{
outp = sock.getOutputStream();
inp = sock.getInputStream();
}
catch (Exception e)
{
rdata = e+" (getstream)";
try
sock.close();
catch (IOException ee) ;
return;
}
try
{
dataout = new DataOutputStream(outp);
datain = new DataInputStream(inp);
}
catch (Exception e)
{
rdata = e+" (Dstream)";
try
sock.close();
catch (IOException ee) ;
return;
}
// Send http request to server and get return data
try
{
// HTTP header
dataout.writeBytes("POST " + script + " HTTP/1.0\r\n");
dataout.writeBytes("Content-type: " + ctype + "\r\n");
dataout.writeBytes("Content-length: " + sdata.length() +
"\r\n");
dataout.writeBytes("\r\n"); // end of header
// POST data
dataout.writeBytes(sdata);
dataout.writeBytes("\r\n");
boolean body = false;
String line;
while ((line = datain.readLine()) != null)
{
if (body)
rdata += "\n" + line;
else if (line.equals("")) // end of header
body = true;
}
}
catch (Exception e)
{
rdata = e+" (write)";
try
sock.close();
catch (IOException ee) ;
return;
}
// close up shop
try
{
dataout.close();
datain.close();
}
catch (IOException e) ;
try
sock.close();
catch (IOException e) ;
}
public void stop() {}
public void paint(Graphics g)
{
StringTokenizer st = new StringTokenizer(rdata, "\n");
int line = 1,
line_sp = getFontMetrics(getFont()).getHeight()+1;
while (st.hasMoreTokens())
{
g.drawString(st.nextToken(), 5, line*line_sp);
line++;
}
}
}
===========
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
US Mail:
-------
Mark Klein, PhD
Information Systems Department
The Applied Research Laboratory
P.O. Box 30
State College, PA 16804-0030 USA
Express Mail Services:
---------------------
Mark Klein, PhD
Information Systems Department
Applied Science Building
Atherton Street
State College, PA 16804-0030 USA
Voice: +1 (814) 863-5381
Fax: +1 (814) 863-1396 (best) or 865-7097
Email: klein@quark.arl.psu.edu
WWW: http://quark.arl.psu.edu/klein-vita.html