Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

49 lines (34 sloc) 0.985 kb

ZeroMQ bindings for versions 2.x, 3.x

ØMQ bindings for node.js.

Installation

$ npm install zeromq-port

Example

server.js:

var zmq = require('zeromq-port');

// publisher = send only
var socket = zmq.createSocket('pub');

var stocks = ["AAPL", "GOOG", "YHOO", "MSFT", "INTC"];

socket.bind("tcp://127.0.0.1:12345", function(err) {
  if (err) console.log(err);
  console.log("bound!");
  setInterval(function() {
    var symbol = stocks[Math.floor(Math.random()*stocks.length)];
    var value = Math.random()*1000;
    socket.send(symbol+" "+value);
    console.log("Sent: "+symbol+" "+value);
  }, 100);
});

client.js:

var zmq = require('zeromq-port');

// subscriber = receive only
var socket = zmq.createSocket('sub');
socket.connect("tcp://127.0.0.1:12345");
socket.subscribe("AAPL");

console.log("connected!");

socket.on('message', function(data) {
  console.log("received data: " + data.toString('utf8'));
});
Jump to Line
Something went wrong with that request. Please try again.