Question

I am working with the node.js example. I have installed openpgm and zeromq 3.2 on my ubuntu 12.10 machine. Here's the code:

var zmq = require('zmq')
  , port = 'epgm://eth0;239.192.1.1:5555';

  var socket = zmq.socket('pub');

  socket.identity = 'publisher' + process.pid;

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

  socket.bind(port, function(err) {
    if (err) throw err;
    console.log('bound!');

    setInterval(function() {
      var symbol = stocks[Math.floor(Math.random()*stocks.length)]
        , value = Math.random()*1000;

      console.log(socket.identity + ': sent ' + symbol + ' ' + value);
      socket.send(symbol + ' ' + value);
    }, 1000);
  });

and the other app:

var zmq = require('zmq') , port = 'epgm://eth0;239.192.1.1:5555';

var socket = zmq.socket('sub');

socket.identity = 'subscriber' + process.pid;

socket.connect(port);

socket.subscribe('AAPL'); socket.subscribe('GOOG');

console.log('connected!');

socket.on('message', function(data) { console.log(socket.identity + ': received data ' + data.toString()); });

I am not sure if I am using the correct multicast addressing. I have tried these apps together in the same machine, and also in another machine in the network. I am pretty sure I have not thought through that part, but I can't seem to find any good explanation about it anywhere. But I expected this to work on the same machine anyway. Any ideas?

PS: Forgot to explain what exactly happens: Basically the push program just pushes all the messages without any error, and the pull program starts but doesn't receive any message.

Was it helpful?

Solution

Not sure if this helps, but I've been experimenting with zmq in node as well and have made some observations:

I am running using four machines: 1: OS X 10.8.3 2: Ubuntu 12.10 in VM (bridged) 3: Ubuntu 12.04 separate machine
4: Ubuntu 12.04 separate machine

When I start the same test server on all machines (not too dissimilar from your code above) Machine 1: sees updates from machine 3 and 4 Machine 2: sees updates from 1, 2, 3, and 4 Machine 3: sees updates from 1, 3, 4 Machine 4: sees updates from 1, 3, 4

so it seems like OS X blocks broadcasts to itself. Ubuntu 12.10 in the VM is getting everyone's but having problems sending (possibly related to running in the VM?) and the other machines are getting their own.

My server/client:

os = require 'os'
zmq = require 'zmq'

client = zmq.socket "sub"
server = zmq.socket "pub"

client.connect "epgm://224.0.0.1:5555", (error) ->
    if error?
        console.log "client error:", error

client.subscribe ""
client.on "message", (buffer) ->
    console.log "received ping:", buffer.toString!

server.bind "epgm://224.0.0.1:5555", (error) ->
    if error?
        console.log "server error:", error
    setInterval ( -> 
        server.send "#{os.hostname!}" 
    ), 1000

process.on "SIGINIT", ->
    client.close!
    server.close!
    process.exit!

OTHER TIPS

epgm and pgm work only for PUB/SUB.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top