-
Notifications
You must be signed in to change notification settings - Fork 3
/
java_socket_bridge.js
50 lines (43 loc) · 1.16 KB
/
java_socket_bridge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Global variables
var java_socket_bridge_ready_flag = false;
// Applet reports it is ready to use
function java_socket_bridge_ready(){
java_socket_bridge_ready_flag = true;
}
// Connect to a given url and port
function socket_connect(url, port){
if(java_socket_bridge_ready_flag){
return get_java_socket_bridge().connect(url, port);
}
else{
on_socket_error("Java Socket Bridge cannot connect until the applet has loaded");
}
}
// Disconnect
function socket_disconnect(){
if(java_socket_bridge_ready_flag){
return get_java_socket_bridge().disconnect();
}
else{
on_socket_error("Java Socket Bridge cannot disconnect until the applet has loaded");
}
}
// Write something to the socket
function socket_send(message){
if(java_socket_bridge_ready_flag){
return get_java_socket_bridge().send(message);
}
else{
on_socket_error("Java Socket Bridge cannot send a message until the applet has loaded");
}
}
// Get something from the socket
function on_socket_get(message){}
// Report an error
function on_socket_error(message){
alert(message);
}
// Get the applet object
function get_java_socket_bridge(){
return document.getElementById('JavaSocketBridge');
}