ndn-js
Version:
A JavaScript client library for Named Data Networking
93 lines (79 loc) • 3.33 kB
HTML
<!--
* Copyright (C) 2014-2018 Regents of the University of California.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* A copy of the GNU Lesser General Public License is in the file COPYING.
*
* author: Chavoosh Ghasemi <chghasemi@cs.arizona.edu>
-->
<!--
This page directly uses Fixed and Cubic pipelines to fetch any NDN segmented content.
-->
<head>
<title>Use Cubic/Fixed Pipeline to fetch data via WebSocket</title>
<script type="text/javascript" src="../../build/ndn.js"></script>
<script type="text/javascript">
var face = new Face({host: "localhost"});
function onComplete(content)
{
console.log("onComplete called.");
console.log("Host: " + face.connectionInfo.toString());
document.getElementById('content').innerHTML +=
"<p style='font-weight:bold; color:green;'>Successfully received the content";
document.getElementById('content').innerHTML += content.buf().toString('binary');
}
function onTimeout(interest)
{
console.log("onTimeout called. Re-expressing the interest.");
console.log("Host: " + face.connectionInfo.toString());
face.expressInterest(interest, onData, onTimeout);
}
function run() {
if (document.getElementById('pipeline').value === "cubic") {
new PipelineCubic
(new Interest(document.getElementById('interest').value), face,
null /*cubic pipeline options*/,
null /*validation key*/,
onComplete, function(errorCode, message) {
console.log("Error " + errorCode + ": " + message);
}).run();
}
else {
new PipelineFixed
(new Interest(document.getElementById('interest').value), face,
{windowSize: 20} /*fixed pipeline options*/,
null /*validation key*/,
onComplete, function(errorCode, message) {
console.log("Error " + errorCode + ": " + message);
}).run();
}
}
</script>
</head>
<body>
<div style="font-size:15px; font-family:monospace; color:slateblue;">Please Enter the Interest name:<br /></div>
<input id="interest" style="border-radius: 3px" type="text" name="INTEREST" size="50" value="/" />
<br>
<select id="pipeline">
<option value="cubic">Cubic Pipline</option>
<option value="fixed">Fixed Pipline</option>
</select>
<br><br>
<button style="margin-top:7px; font-style:italic; border-radius: 7px;" id="testBtn" onclick="run()">Fetch Content</button>
<div id="content"><p>Content: </p></div>
</body>
</html>