Domanda

NodeJS v.0.10.X is not backwards compatible with v0.8.X for multicast.

bind seems to have changed from synchronous to async.

I'm currently working around the issue with a horrible fudge:

https://github.com/chrisdew/multicast-eventemitter/blob/master/lib/multicast-eventemitter.js#L87

Is there a mistake in how I'm using the API, or is backwards compatibility broken here?

If I use the v0.10.X code with NodeJS v0.8.X I get no messages being received (I assume the call to 'bind' is synchronous here, and doesn't call the function provided.

If I use the v0.8.X code with NodeJS v0.10.X I get an error:

dgram.js:354
    throw errnoException(process._errno, 'setMulticastTTL');
          ^
Error: setMulticastTTL EBADF
    at errnoException (dgram.js:439:11)
    at Socket.setMulticastTTL (dgram.js:354:11)
    at MulticastEventEmitter.addListener (/home/chris/Dropbox/multicast-eventemitter/lib/multicast-eventemitter.js:96:14)
    at Object.<anonymous> (/home/chris/Dropbox/multicast-eventemitter/examples/loopback.js:17:9)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

Can anyone see a way to remove this horrendous fudge?

È stato utile?

Soluzione

Yes, it is no longer synchronous. You can check the docs too.

Important note: the behavior of dgram.Socket#bind() has changed in v0.10 and is always asynchronous now.

If you have code that looks like this:

var s = dgram.createSocket('udp4');
s.bind(1234);
s.addMembership('224.0.0.114');

You have to change it to this:

var s = dgram.createSocket('udp4');
s.bind(1234, function() {
  s.addMembership('224.0.0.114');
});

It will be like this so you would have to change your code.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top