0.1.4 • Published 8 years ago

jsonbus v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

#JSONbus Very fast, async and simple JSON message passing over TCP with auto reconnecting client and the ability to have multiple server responses to client's single request.

Server

.createServer() accepts default net.createServer options

var bus= require('jsonbus')
var server= bus.createServer().listen(8181)
server.on('request', function(res, callback)
{
	if( callback )
		callback({pong: 1, haveMore: false})
})

Client

var bus= require('jsonbus')
var client= bus.connect(8181)

// no server response aka "fire and forget"
client.request({ping: 1, times: 1})

// single server response
client.request({ping: 1, times: 1}, function(res){
	 console.log(res)
})

// multiple server responses
client.request({ping: 5, times: 5}, {timeout: 250, keepAlive: true, callback: function(res, end)
{
	 if( !res.haveMore)
	 {
	 	// end() available when keepAlive= true
	 	// use when server need to send multiple responses
		end()
	 }
}})

bus.connect(options)

client.request(object, options)

  • object any JSON.stringify-able object
  • options a callback function or options object {callback, keepAlive, timeout} callback keepAlive client must manually call the end() on server's response to cleanup requests data * timeout overrides .connect's requestTimeout

Benchmarking

Below is Mac Air 2013 results (25k send->receive->reply->receive on a single core)

 $ node test.js 25000
 > client sent and received 25000 responses in 0.892473207 seconds

Installation

npm install jsonbus
0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago