Meki Cherkaoui | 97e7a59 | 2012-04-14 02:50:06 -0700 | [diff] [blame^] | 1 | // Global variables
|
| 2 | var java_socket_bridge_ready_flag = false;
|
| 3 |
|
| 4 | var ndnport =null;
|
| 5 | var ndnurl=null;
|
| 6 |
|
| 7 | // Applet reports it is ready to use
|
| 8 | function java_socket_bridge_ready(){
|
| 9 | java_socket_bridge_ready_flag = true;
|
| 10 | }
|
| 11 |
|
| 12 | function createRoute(url, port){
|
| 13 | ndnport = port;
|
| 14 | ndnurl=url;
|
| 15 | }
|
| 16 |
|
| 17 | // Connect to a given url and port
|
| 18 | function 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 |
|
| 45 | function 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
|
| 53 | function on_socket_get(message){}
|
| 54 |
|
| 55 | // Report an error
|
| 56 | function on_socket_error(message){
|
| 57 | alert(message);
|
| 58 | }
|
| 59 |
|
| 60 | // Get the applet object
|
| 61 | function get_java_socket_bridge(){
|
| 62 | return document.getElementById('JavaSocketBridge');
|
| 63 | } |