Simple UDP based protocol for service discovery implemented in pure JS.
npm install @ionic/discoverSimple UDP based protocol for service discovery implemented in pure JS. It is
not mDNS or bonjour, but it tries to accomplish the same thing.
It uses a JSON based textual format:
``ts
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);
`
| key | description
|------------|-------------
| t | unix timestamp in secondid
| | unique id for this sessionname
| | name of the announced servicehost
| | hostname of the machine announcing the serviceip
| | ipv4 addressport
| | tcp port of the announced servicecommPort
| | optional websocket port of the communication server
``
npm install @ionic/discover
`ts
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();
``