1.0.2 • Published 6 years ago
msgpack-rpc-lite v1.0.2
msgpack-rpc-lite
Implementation of MessagePack-RPC with msgpack-lite
Usage
createServer(serverOptions)
Creates a new MessagePack-RPC server.
serverOptions
<Object> See net.createServer([options][, connectionListener])codecOptions
<Object>encode
See Custom Codec Optionsdecode
See Custom Codec Options
- Returns: <net.Server>
Server event: method
Emitted when a new connection is made.
- <Array> request parameters.
- <Function> If a request is received, a callback function is passed.
- To return the results to the client, pass
null
as the first argument and response parameters as the second argument. - If an error occurs, pass it to the first argument.
- To return the results to the client, pass
createClient(port, host, codecOptions)
Initiates a MessagePack-RPC client.
port
<number> Port the socket should connect to.host
<string> Host the socket should connect to. Default:'localhost'
timeout
<number> Sets the socket to timeout after timeout milliseconds of inactivity on the socket. If timeout is 0, then the existing idle timeout is disabled. Default:0
codecOptions
<Object>encode
See Custom Codec Optionsdecode
See Custom Codec Options
- Return: <Client>
client.request(method, ...args)
method
<string>- Return: <Promise>
client.notify(method, ...args)
method
<string>- Return: <Promise>
Examples
Server
const rpc = require('msgpack-rpc-lite'); const server = rpc.createServer().on('say', (params, callback) => { const [ message ] = params; callback(null, `hello ${ message }`); }); server.listen(9199);
Client
const rpc = require('msgpack-rpc-lite'); const client = rpc.createClient(9199, 'localhost'); client.request('say', [ 'world' ]).then(([ response ]) => { console.log(response); // hello world })
Compatibility Mode
Set true
to useraw
of encode
/decode
of Codec-options.
Client
const codecOptions = { encode: { useraw: true }, decode: { useraw: true } }; const client = rpc.createClient(9199, 'localhost', 0, codecOptions);
See also:
- https://github.com/kawanet/msgpack-lite#compatibility-mode
- https://github.com/msgpack/msgpack/blob/master/spec.md#upgrading-messagepack-specification
See also
1.0.2
6 years ago
1.0.1
6 years ago
1.0.1-0
6 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
1.0.0
6 years ago
0.1.3
6 years ago
0.1.3-0
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago
0.0.7
6 years ago
0.0.6
6 years ago
0.0.5
6 years ago
0.0.4
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago