Skip to main content

Create a Node.js client

Baseline: IOSignal 7.2.0. Start the server from the quickstart.

npm install --save-exact iosignal@7.2.0

Save as client.mjs:

import { IO } from 'iosignal';

const io = new IO('ws://localhost:7777');
io.on('room#chat', (tag, message) => {
console.log('Received:', tag, message);
});
io.on('ready', () => {
console.log('CID:', io.cid);
io.subscribe('room#chat');
io.signal('room#chat', 'Hello from Node.js');
});
io.on('change', state => console.log('State:', state));
io.on('error', console.error);

Run node client.mjs. Start it in another terminal to exchange messages through the same channel. Subscribing before sending also lets the client receive its first message. The handler is registered once, and subscriptions are repeated on reconnection.

See client API for connection and cleanup methods. Browser apps use a different import.