I'm trying to convert a complex Java applet to JavaScript. The applet does all sorts of magic with communicating on a TCP socket, which I will need to emulate in JavaScript. The TCP magic is itself quite complicated, so I'd rather do that later and get the graphical part of the applet working first. The communication over the TCP socket tells the applet what to draw, so depending on the data on the socket, the applet will read/write different values.
My current plan of attack is:
- Pass request header to JavaScript as parameters (working) as well as needed data from socket depending on the request type
- Parse header params/data sent in JS and create objects accordingly
- Return value to calling Java function with an array of bytes to be written to the TCP socket
I'm stuck on the last part. If I return an array of bytes, how can I convert that to a byte[] or similar? Is the value passed back a proper Java array or is it some kind of object hash?
Java:
void callJavaScript(Applet app) {
String[] params = {"blah", "cool"};
JSObject win = JSObject.getWindow(app);
Object ret = win.call("someFunction", params);
// what is ret?
}
JavaScript:
function someFunction (blah, cool) {
return [5, 7, 12, 2];
}
Note:
The complicated Java applet is multi-threaded, so just calling some function in the applet is non-trivial.
retshould be a netscape.javascript.JSObject. If it is a array in javascript did you try to useret.getSlot?