1

Has anyone created a working setup where OSC is being sent between machines on a LAN using Node.js? Ideally, using Colin Clark's osc.js package?

I have what I think should be a pretty simple example, except that it doesn't work - I get an EADDRNOTAVAIL error, which implies that the remote address isn't available. I can ping the other laptop successfully, however.

Here's the code and the error, for reference:

Sending code (laptop at 192.168.0.5):

var osc = require("osc");

var udp = new osc.UDPPort({
    localAddress: "127.0.0.1", // shouldn't matter here
    localPort: 5000, // not receiving, but here's a port anyway
    remoteAddress: "192.168.0.7", // the other laptop
    remotePort: 9999 // the port to send to
});

udp.open();

udp.on("ready", function () {

    console.log("ready");
    setInterval(function () {
        udp.send({
            address: "/sending/every/second",
            args: [1, 2, 3]
        })
    }, 1000);
});

Receive code (on laptop at 192.168.0.7):

var osc = require("osc");
var udp = new osc.UDPPort({
    localAddress: "192.168.0.7",
    localPort: 9999
});

udp.open();

udp.on("ready", function () {
    console.log("receiver is ready");
});

udp.on("message", function(message, timetag, info) {
   console.log(message); 
});

Here's the error I get when I run the sending code:

ready
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: send EADDRNOTAVAIL 192.168.0.7:9999
    at Object.exports._errnoException (util.js:907:11)
    at exports._exceptionWithHostPort (util.js:930:20)
    at SendWrap.afterSend [as oncomplete] (dgram.js:345:11)
jwn
  • 21
  • 4

1 Answers1

2

The issue is that the osc.UDPPort that you are using to send OSC messages has its localAddress bound to the loopback address, which is limited to connections within your local computer. As a result, your sender can't find your receiver.

The solution is to bind your sender's localAddress to an appropriate network interface. If your 192.168.0.5 IP address is stable and you don't need to worry about it changing when you connect your laptops to another network (say, for a gig or a gallery installation), then you can just use that. Otherwise, you might want to use an mDNS name ("foo.local") or the "all interfaces" address, 0.0.0.0.

This change to your "Sender code" worked for me when I tried it on my network:

var osc = require("osc");

var udp = new osc.UDPPort({
    localAddress: "0.0.0.0", // Totally does matter here :)
    localPort: 5000,
    remoteAddress: "192.168.0.7", // the other laptop
    remotePort: 9999 // the port to send to
});

udp.open();

udp.on("ready", function () {
    console.log("ready");
    setInterval(function () {
        udp.send({
            address: "/sending/every/second",
            args: [1, 2, 3]
        })
    }, 1000);
});

As a side note, osc.js's behaviour does differ from a regular Node.js UDP socket, since if the local address is omitted Node will default to 0.0.0.0. An osc.UDPPort, however, will always bind to 127.0.0.1 if localAddress is omitted (which seemed a little safer to me when originally implementing osc.js, but I can see how it might be confusing).

This issue is also discussed on the osc.js issue tracker, and I will update the documentation to prevent the kind of confusion you encountered here. Best of luck with your project!

  • Unfortunately I spent 4 days searching for this and it was staring at me the whole time in my UDPPort local address. Thanks Colin. This fixed it! – Architek1 Apr 20 '17 at 03:51