RMI Client (RPC Client)
The client side library for the RMI Server for making Remote Procedure Calls.
The RPC Client uses socket.io for communication over network.
Installation
As a common js module
The library could be used as a common js module as a node client or in a browser application through bundlers like webpack or browserify. The socket.io-client library is not bundled together so you will have to install the socket.io-client library as well.
$ npm install --save socket.io-client
$ npm install --save socket.io-rmi-client
UMD build through npmcdn
The UMD build of the library is available at npmcdn:
Usage
CommonJS module
The RMI Client could be used as a CommonJS modules when used in a node as a client or in browsers through webpack/browserify or in a ReactNative project.
'use strict';;; // Connect to the RPC Server at the given address and port// In case of browsers, the second argument could be emptyconst client = RMIClient;client { // This callback is invoked as soon as a remote connection is established. // The RPC calls could now be carried on the remoteInstance remoteInstance; // make rpc call with callbacks remoteInstance; // get instances than can further make RPC calls remoteInstance;}); client { // If the client gets disconnected from the server, this method is invoked, // this could be taken as an opportunity to update the UI with the // disconnected state.}
Using EventHandler
The RPC calls can also be used to pass EventHandler instances to the server. The server could raise events on this server as and when needed.
// Using Class for creating event handlers'use strict';const RMIClient = ;const io = ; // The EventHandler class must be extended from RMIClient.EventHandlerEventHandler // The event methods should be prefixed with 'on' { } RMIClient { instance;}
// Using without declaring classes, most likely using UMD modulesRMIClient { const eventHandler = RMIClient; eventHandler { // This event will be raised from the server } instance;}
More Documentation
For further more documentation and use cases, check out the RMI Server.