Socket
Socket
Sign inDemoInstall

json-rpc-client

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    json-rpc-client

Very fast and lightweight persistent promise JSON RPC 2.0 client implementation over TCP and Unix socket


Version published
Weekly downloads
80
decreased by-17.53%
Maintainers
1
Install size
18.9 kB
Created
Weekly downloads
 

Readme

Source

json-rpc client

GitHub license
NPM

JSON-RPC 2.0 TCP implementation with persistent connections using promises - very fast and without dependencies

Installation

npm install json-rpc-client

Example usage

Native promise

var jsonrpc = require('json-rpc-client')

// create client and connect
var client = new jsonrpc({ port: 7070, host: '127.0.0.1'})
client.connect().then(function()
{
    // send json rpc
    client.send('add', [1,2]).then(function(reply)
    {
        // print complete reply
        console.log(reply)
    },
    //transport errors
    function(error)
    {
        console.error(error)
    })
},
function(error)
{
    console.error(error)
})

Generators (using co)

var jsonrpc = require('json-rpc-client')

// create client and connect
var client = new jsonrpc({ port: 7070, host: '127.0.0.1'})

try
{
    yield client.connect()

    // send json rpc
    var reply = yield client.send('add', [1,2])

    // print complete reply
    console.log(reply)
}
catch(error)
{
    console.error(error)
}

API

var jsonrpc = require('./jsonrpc')

jsonrpc (options)

Creates a new RPC connection object.

Options:

  • host: Host the client should connect to. Defaults to '127.0.0.1'.
  • port: Port the client should connect to. Defaults to '7070'.

connect

Returns promise which resolves after the connection to the specified host is ready

send (methodName, parameters, notification)

Sends json data through persisted tcp connection.

methodName: string

parameters: Object/Array with parameters

notification: true/false to make notification request (no reply)

  • Promise - object containing reply data along with error

close

Closes RPC connection and returns promise afterwards.

Event 'error'

  • 'Error Object'

Emitted when an error occurs.

Event: 'close'

  • 'had_error' 'Boolean' true if the socket had a transmission error

Emitted once the RPC connection socket is fully closed. The argument 'had_error' is a boolean which says if there was an error.

Keywords

FAQs

Last updated on 27 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc