Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ndn/ws-transport

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndn/ws-transport

NDNts: WebSocket Transport

  • 0.0.20200909
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@ndn/ws-transport

This package is part of NDNts, Named Data Networking libraries for the modern web.

This package implements a WebSocket transport. It works in both Node and browser.

You can create a forwarder face that uses WebSocket transport with WsTransport.createFace() function. To create a WebSocket transport without wrapping into L3Face, use WsTransport.connect() function.

import { WsTransport } from "@ndn/ws-transport";

// other imports for examples
import { Endpoint } from "@ndn/endpoint";
import { Data, Interest, Name } from "@ndn/packet";
(async () => {
if (process.env.CI) { return; }

// Create a WebSocket face.
// Unless other specified, the face is added to the default Forwarder instance.
// You may set an alternate Forwarder instance in the first argument.
const uplink = await WsTransport.createFace({}, "wss://hobo.cs.arizona.edu/ws/");

// The face is ready for receiving incoming packets. To make the forwarder send Interests
// to it, add a route toward the face.
uplink.addRoute(new Name("/ndn"));

// Construct an Endpoint on the default Forwarder instance.
const endpoint = new Endpoint();

// We can now send Interests and retrieve Data.
let seq = Math.floor(Math.random() * 99999999);
for (let i = 0; i < 5; ++i) {
  try {
    const interest = new Interest(`/ndn/edu/arizona/ping/NDNts/${seq++}`);
    console.log(`<I ${interest.name}`);
    const data = await endpoint.consume(interest);
    console.log(`>D ${data.name}`);
  } catch (err) {
    console.warn(err);
  }
}

// In case a socket error occurs, the transport will attempt to reconnect automatically,
// although packets transmitted during that time would be lost. The logic of reconnecting
// is implemented in L3Face class from @ndn/l3face package.

// When the face is no longer needed, close it.
uplink.close();
})();

Keywords

FAQs

Package last updated on 10 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc