Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @ionic/discover with all npm packages installed. Try it out:

var discover = require("@ionic/discover")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@ionic/discover v2.0.1

Simple UDP based protocol for service discovery implemented in pure JS.

Ionic Discover

Simple UDP based protocol for service discovery implemented in pure JS. It is not mDNS or bonjour, but it tries to accomplish the same thing.

Spec

It uses a JSON based textual format:

const message = {
  t: now,
  id: 'unique',
  name: this.name,
  host: os.hostname(),
  ip: iface.address,
  port: number1,
  commPort: number2
};

return 'ION_DP' + JSON.stringify(message);
keydescription
tunix timestamp in second
idunique id for this session
namename of the announced service
hosthostname of the machine announcing the service
ipipv4 address
porttcp port of the announced service
commPortoptional websocket port of the communication server

Installation

npm install @ionic/discover

Usage

import { Publisher } from '@ionic/discover';

const namespace = 'your-service';
const serviceName = 'Ionic thing!';
const tcpPort = 8100;
const service = new Publisher(namespace, serviceName, tcpPort);

await service.start();
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free