Skip to content

routekickr/nanomsg.iojs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nanomsg.iojs

nanomsg for iøjs https://github.com/nanomsg/nanomsg

description

an iojs interface to nanomsg sockets with a pipeable stream option.

prerequisites

install nanomsg c lib and iojs.

install

$ npm i iojs-nanomsg

use

var nano = require('iojs-nanomsg')
var pub = nano.socket('pub')
var addr = 'tcp://127.0.0.1:5555'

pub.bind(addr)

//start a broadcast interval
setInterval(function(){
  pub.send('hello from nanømsg!')
}, 100)

var sub1 = nano.socket('sub',{
  //set asBuffer option for strings. default is true
  asBuffer:false
})
sub1.on('msg',function(msg){
  //local handle converted to V8::String direct from nanomsg nn_recv()
  console.log(msg)
})
sub1.connect(addr)

var sub2 = nano.socket('sub', {
  //for a pipeable stream pass `{ stream: true }` with the socket type
  stream: true
})

//stream option disables onmessage emitter (for perf reasons)
//there's a readable/writable stream depending on the socket type
var subStream = sub2.stream
sub2.connect(addr)

subStream.on('data',function(msg){
  console.log(String(msg))
})

#test

$ make clean && make && make check

tested on node v0.08.x and up

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 63.4%
  • C++ 30.3%
  • C 4.1%
  • Makefile 1.2%
  • Python 1.0%