blob: ee91dcb99de540b3bdb267906ff12af85a175433 [file] [log] [blame]
Meki Cherkaoui97e7a592012-04-14 02:50:06 -07001// Global variables
2var java_socket_bridge_ready_flag = false;
3
4var ndnport =null;
5var ndnurl=null;
6
7// Applet reports it is ready to use
8function java_socket_bridge_ready(){
9 java_socket_bridge_ready_flag = true;
10}
11
12function createRoute(url, port){
13 ndnport = port;
14 ndnurl=url;
15}
16
17// Connect to a given url and port
18function queryPrefix(message){
19 if(ndnport!=null && ndnurl!=null){
20 var newMessage ='';
21
22 enc = new BinaryXMLEncoder();
23
24 //encoder.beginEncoding();
25
26
27 int = new Interest(new ContentName(['PARC','%00','%01','%02']));
28
29 int.encode(enc);
30
31 var hex = byte2hex(enc.ostream);
32
33 console.log('Conect and start '+ ndnurl +':'+ndnport+'-'+message);
34
35 return get_java_socket_bridge().connectAndStart(ndnurl,ndnport,message);
36 }
37 else{
38 console.log('ERROR URL OR PORT NOT SET');
39 return '';
40 }
41
42}
43
44
45function byte2hex(bytearray){var result = [];
46 var length = bytearray.length;
47 for (var i = 0;i < length;++i) {
48 result.push(AddFillerLeft(bytearray[i].toString(16).toUpperCase(), '0', 2));
49 }
50 return result.join('');
51}
52// Get something from the socket
53function on_socket_get(message){}
54
55// Report an error
56function on_socket_error(message){
57 alert(message);
58}
59
60// Get the applet object
61function get_java_socket_bridge(){
62 return document.getElementById('JavaSocketBridge');
63}