1.0.3 • Published 3 years ago

@ovistek/rpc-net v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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.

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.1.0

3 years ago