Skip to content

Lightweight JS Remote Procedure Call (RPC) Framework using Socket.io

License

Notifications You must be signed in to change notification settings

OvisTek/rpc-net

Repository files navigation

OvisTek Logo

Twitter: @OvisTek Codacy Badge install size NPM License

Lightweight JS Remote Procedure Call (RPC) Framework using Socket.io


rpc-net allows defining JavaScript/TypeScript functions on a Server or Client environment and executing them from either context. Built using Socket.io.

Installation

  • Install using npm
npm install @ovistek/rpc-net

Usage

Define server-side code using the following snippet and call it server.js

const { ServerRPC } = require("@ovistek/rpc-net");

// host a local server on port 3000
const server = new ServerRPC();
server.connect(3000);

// define a local function on the server
// this will be called by the client
server.local.sayHello = (append) => {
    return "Server Says " + append;
};

Define client-side code using the following snippet and call it client.js

const { ClientRPC } = require("@ovistek/rpc-net");

const client = new ClientRPC();
// connect to a hosted local server on port 3000
client.connect("http://localhost", 3000);

// call a pre-defined function on the remote server
client.remote.sayHello("Hello World!").then((value) => {
    console.log(value);
}).catch((err) => {
    console.error(err);
});
  • Run the server via node server.js
  • Run the client via node client.js

Output should be Server Says Hello World!

Acknowledgements

This tool relies on the following open source projects.

About

Lightweight JS Remote Procedure Call (RPC) Framework using Socket.io

Resources

License

Stars

Watchers

Forks

Packages

No packages published