socket-rpc

raw JSON →
1.0.3 verified Fri May 01 auth: no javascript maintenance

A simple RPC framework for Node.js using socket.io that follows a server-slave model. Version 1.0.3 is the latest stable release. It allows the server to call functions registered on slave clients via WebSocket. Key differentiators: lightweight, minimal API, built on socket.io. Note: The library is somewhat outdated and relies on socket.io v1.x, which may have compatibility issues with newer versions.

error Cannot find module 'socket-rpc'
cause Package not installed
fix
npm install socket-rpc --save
error TypeError: rpc.run(...).then is not a function
cause run() returns undefined if slave not connected or not registered
fix
Ensure slave is connected and registered before server calls run().
error Error: listen EADDRINUSE :::8000
cause Port already in use
fix
Use a different port or kill existing process.
gotcha Requires socket.io v1.x compatibility; socket.io v2+ may break.
fix Pin socket.io to version 1.x in package.json.
breaking No error handling for run() calls; rejected promises will cause unhandled rejections.
fix Add .catch() to run() promises or handle errors on the slave side.
deprecated The library has not been updated since 2018; consider using a modern alternative like uWebSockets.js or raw socket.io RPC.
fix Evaluate if active development is needed; fork or migrate.
npm install socket-rpc
yarn add socket-rpc
pnpm add socket-rpc

Demonstrates creating a server and slave, registering a function on slave, and calling it from the server.

import http from 'http';
import { RPCServer } from 'socket-rpc';
import { RPCSlave } from 'socket-rpc';

// Server
const server = http.createServer();
const rpc = RPCServer(server);
rpc.getServer(); // returns socket.io server instance

// Slave (client)
const slave = RPCSlave({
  url: 'http://localhost:8000',
  id: 0,
  name: 'example'
});
slave.register('greet', name => `Hello, ${name}`);

// Then server can call:
rpc.run('0', 'greet', 'World').then(msg => console.log(msg));

server.listen(8000);