modular-json-rpc
Version:
Modular JSON-RPC 2.0 library that allows easy addition of transports
26 lines (18 loc) • 642 B
JavaScript
const RPC = require('../');
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:8080');
ws.on('open', async () => {
console.log("Websocket connected.");
// Create transport interface via websocket
var transport = new RPC.WSTransport(ws);
// Create RPC node
var node = new RPC.RPCNode(transport);
// Other node will call back and request a name
node.bind('getname', () => {
return "World";
});
// Call hello method without providing name
var result = await node.call('hello');
console.log(`Response: ${result}`);
process.exit();
});