ws-remoting
A library for remote procedure call using websockets and promises. This library was built with the intention of doing rpc like method invocations from javascript running on a client browser. The main concept is:
- Connect to a server using websockets
- Send a message to the server and return a promise to the caller
- Wait for the server to respond
- Resolve the promise with the result of that call.
Broadcast
In addition to sending requests and receiving responses from the server, we added broadcast support. That is, a server can send messages to all clients to notify changes. That comes in handy when developing real time systems.
Tutorial
This is a simple tutorial to help you get started. More advanced examples will be provided on the samples repository.
The server
Set up a very simple server, register a test action to be invoked from the client.
Use JsonRpcServer. This is expected to run on a nodejs environment.
const http = ;const remotingServer = ; // Create a serverconst server = http; // Create a remoting serverconst rs = server: server ; // Register the actions that can be executed remotelyrs; // Start listeningserver;console;
The client
Set up a very simple client, connect to the server and invoke a remote method.
Use WsRemotingClient. This is expected to use native WebSocket from a browser.
;const remoting = "ws://localhost:1337";remoting ;