blob: 015eeb1398dd389b38d41953cfced3ebdd866fb8 [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">
Jeff Burke92dd8e42012-12-08 11:40:31 -08004<!--
5 See COPYING for copyright and distribution information.
6-->
Jeff Thompson287a3182012-11-11 18:12:20 -08007<html xmlns = "http://www.w3.org/1999/xhtml">
8<meta charset="UTF-8">
9
10<head>
11 <title>NDN Get via WebSocket</title>
12
Wentao Shang0e291c82012-12-02 23:36:29 -080013 <script type="text/javascript" src="../tools/build/ndn-js.js"></script>
Jeff Thompson287a3182012-11-11 18:12:20 -080014
15 <script type="text/javascript">
Wentao Shang7eb8c402012-11-19 13:30:44 -080016 var ndn = new NDN({port:9696});
Jeff Thompson5b265a72012-11-12 01:13:08 -080017 ndn.transport.connectWebSocket(ndn);
Jeff Thompson287a3182012-11-11 18:12:20 -080018
19 var AsyncGetClosure = function AsyncGetClosure() {
20 // Inherit from Closure.
21 Closure.call(this);
22 };
23
24 AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
Wentao Shangc0311e52012-12-03 10:38:23 -080025 //console.log("Closure.upcall() executed.");
Jeff Thompson287a3182012-11-11 18:12:20 -080026 if (kind == Closure.UPCALL_FINAL) {
27 // Do nothing.
28 } else if (kind == Closure.UPCALL_CONTENT) {
Jeff Thompson287a3182012-11-11 18:12:20 -080029 var content = upcallInfo.contentObject;
Wentao Shang2b740e62012-12-07 00:02:53 -080030 //console.log(content.name);
Jeff Thompson287a3182012-11-11 18:12:20 -080031 nameStr = escape(content.name.getName());
Wentao Shang2b740e62012-12-07 00:02:53 -080032 document.getElementById('content').innerHTML += "<p>Name string: " + nameStr + "</p>";
33 document.getElementById('content').innerHTML += "<p>Content buffer length: " + content.content.length + "</p>";
34 //console.log("In callback, nameStr: " + nameStr);
35 //console.log("In callback, content: ");
36 //console.log(content);
37 document.getElementById('content').innerHTML += contentObjectToHtml(content);
Wentao Shangc0311e52012-12-03 10:38:23 -080038 } else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
39 console.log("Closure.upcall called with interest time out.");
Jeff Thompson287a3182012-11-11 18:12:20 -080040 }
41 return Closure.RESULT_OK;
42 };
43
44
45 function run() {
Jeff Thompson5b265a72012-11-12 01:13:08 -080046 ndn.expressInterest(new Name(document.getElementById('interest').value), new AsyncGetClosure());
Jeff Thompson287a3182012-11-11 18:12:20 -080047 }
48
49 </script>
50
51</head>
52<body >
53
54 <form>
55 Please Enter an Interest:<br />
56 <input id="interest" type="text" name="INTEREST" size="50" value="/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY" />
57 </form>
58
59 <button onclick="run()">Fetch Content</button>
60
61 <p id="content">Content: <br/></p>
62
63</body>
64</html>