blob: eff7aeee181242826bc57534a8be10cf96276eea [file] [log] [blame]
Jeff Thompson287a3182012-11-11 18:12:20 -08001<?xml version = "1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3"DTD/xhtml1-strict.dtd">
4<html xmlns = "http://www.w3.org/1999/xhtml">
5<meta charset="UTF-8">
6
7<head>
8 <title>NDN Get via WebSocket</title>
9
Wentao Shang0e291c82012-12-02 23:36:29 -080010 <script type="text/javascript" src="../tools/build/ndn-js.js"></script>
Jeff Thompson287a3182012-11-11 18:12:20 -080011
12 <script type="text/javascript">
Wentao Shang7eb8c402012-11-19 13:30:44 -080013 var ndn = new NDN({port:9696});
Jeff Thompson5b265a72012-11-12 01:13:08 -080014 ndn.transport.connectWebSocket(ndn);
Jeff Thompson287a3182012-11-11 18:12:20 -080015
16 var AsyncGetClosure = function AsyncGetClosure() {
17 // Inherit from Closure.
18 Closure.call(this);
19 };
20
21 AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
Wentao Shangc0311e52012-12-03 10:38:23 -080022 //console.log("Closure.upcall() executed.");
Jeff Thompson287a3182012-11-11 18:12:20 -080023 if (kind == Closure.UPCALL_FINAL) {
24 // Do nothing.
25 } else if (kind == Closure.UPCALL_CONTENT) {
Jeff Thompson287a3182012-11-11 18:12:20 -080026 var content = upcallInfo.contentObject;
Wentao Shang2b740e62012-12-07 00:02:53 -080027 //console.log(content.name);
Jeff Thompson287a3182012-11-11 18:12:20 -080028 nameStr = escape(content.name.getName());
Wentao Shang2b740e62012-12-07 00:02:53 -080029 document.getElementById('content').innerHTML += "<p>Name string: " + nameStr + "</p>";
30 document.getElementById('content').innerHTML += "<p>Content buffer length: " + content.content.length + "</p>";
31 //console.log("In callback, nameStr: " + nameStr);
32 //console.log("In callback, content: ");
33 //console.log(content);
34 document.getElementById('content').innerHTML += contentObjectToHtml(content);
Wentao Shangc0311e52012-12-03 10:38:23 -080035 } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
36 console.log("Closure.upcall called with interest time out.");
Jeff Thompson287a3182012-11-11 18:12:20 -080037 }
38 return Closure.RESULT_OK;
39 };
40
41
42 function run() {
Jeff Thompson5b265a72012-11-12 01:13:08 -080043 ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure());
Jeff Thompson287a3182012-11-11 18:12:20 -080044 }
45
46 </script>
47
48</head>
49<body >
50
51 <form>
52 Please Enter an Interest:<br />
53 <input id="interest" type="text" name="INTEREST" size="50" value="/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY" />
54 </form>
55
56 <button onclick="run()">Fetch Content</button>
57
58 <p id="content">Content: <br/></p>
59
60</body>
61</html>