You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A main goal of this project is to have the JSON-RPC server and client support __bidirectional JSON-RPC requests over a single WebSocket connection.__Simply put, it makes it possible to have a JSONRPC __Server__in the browser and a separate one in the back-end.
7
+
A main goal of this project is to have the JSON-RPC server and client support __bidirectional JSON-RPC requests over a single WebSocket connection.__In short, it makes it possible to have a JSONRPC __Server__on the client side, or on both sides at once.
8
8
9
9
This library is tested in __browsers__ (>= IE10) and in __Node.js__ (>=7.8).
10
10
11
+
Very simple usage allows for very easy application development:
12
+
* export methods in an endpoint (which extends JSONRPC.EndpointBase), and call those method remotely through a client (which extends JSONRPC.Client);
13
+
* on bidirectional transports, there may be endpoints at both ends of a connection, or reversed roles (TCP client is a JSONRPC server, while TCP server is JSONRPC client).
11
14
12
15
## Transports
13
16
14
-
Both the server and client support two __transports, HTTP and WebSocket__, and allow more through plugin extensibility.
17
+
These transports are already implemented, and they all offer promise-based asynchronous method invocations:
15
18
19
+
| Transport | Type | Browser | Node.js | Serialization |
| ProcessStdIO | one-way, IPC, new child process per call ||[Process](https://nodejs.org/api/process.html#process_process)| JSON |
25
+
16
26
#### WebSocket
17
27
18
28
__Any WebSocket implementation may be used__, as handling of the HTTP server and WebSocket is external to these JSONRPC classes.
@@ -21,12 +31,18 @@ For WebSocket client support in Node.js and browsers, `JSONRPC.Plugins.Client.We
21
31
22
32
On the Node.js side, this library is tested to work with [websockets/ws](https://github.com/websockets/ws). Other `WebSocketServer` implementations are supported if API compatible with `websockets/ws` (constructor and events), or made compatible through an adapter.
23
33
24
-
There is a wrapper for [uWebSockets](https://github.com/uWebSockets/uWebSockets) in `JSONRPC.WebSocketAdapters.uws.WebSocketWrapper`. All obtained `uws.WebSocket` instances (from the `connection` event, or instantiated directly) must be wrapped (and thus replaced) with an instance of this class.
34
+
There is a wrapper for [uWebSockets](https://github.com/uWebSockets/uWebSockets) in `JSONRPC.WebSocketAdapters.uws.WebSocketWrapper`. All obtained `uws.WebSocket` instances (from the `connection` event, or instantiated directly) must be wrapped (and thus replaced) with an instance of this class. According to localhost benchmarks of this library, ws performs better than uws. __Warning:__ uws is buggy when calling .close() on the server (segmentation fault or infinite hang) and it also immediately closes connections with an empty reason string if very large payloads are sent. See `tests/uws_bug*`.
25
35
26
36
#### HTTP
27
37
28
38
`JSONRPC.Client` has embeded support for HTTP requests, through [fetch](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) (polyfills for older browsers exist, and work just fine). `JSONRPC.Server` has the `attachToHTTPServer` method.
29
39
40
+
#### Worker
41
+
For Worker client support in Node.js and browsers, `JSONRPC.Plugins.Client.WorkerTransport` and `JSONRPC.BidirectionalWorkerRouter` accept Node.js [cluster.Worker](https://nodejs.org/api/cluster.html#cluster_class_worker) or standard browser [Worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker) class instances.
42
+
43
+
See `tests/Tests/AllTests.runClusterTests()` and `tests/Browser/index.html` for an example of how to setup servers and clients for master-worker asynchronous communication.
44
+
45
+
30
46
#### Other
31
47
32
48
It is easy to support other transports, see `JSONRPC.Plugins.Client.WebSocketTransport` for an example.
0 commit comments