colinbdclark / osc.js-examples

Sample code illustrating how to use osc.js in a variety of scenarios.
104 stars 28 forks source link

UDP broadcast example #12

Closed jonasbarsten closed 6 years ago

jonasbarsten commented 6 years ago

Hi.

Do you have an example on how to broadcast with osc.UDPPort?

I tried to substitute the address with the network mask (255.255.0.0) and I tried to remove the address alltogheter with no luck.

var udpPort = new osc.UDPPort({
  localAddress: "0.0.0.0",
  localPort: 57121,
  metadata: true,
  broadcast: true
});

udpPort.open();

udpPort.on("ready", function () {
  udpPort.send({
    address: "/s_new",
    args: [
      {
        type: "s",
        value: "default"
      },
      {
        type: "i",
        value: 100
      }
    ]
  }, "255.255.0.0", 8050);
});
jonasbarsten commented 6 years ago

Ah, figured it out.

For further reference:

  1. Enable broadcast (broadcast: true)
  2. Replace the address with the following:
    • If your network-mask is 255.255.255.0 and your IP-range is 192.168.1.x:
    • 192.168.1.255
    • If your network-mask is 255.255.0.0 and your IP-range is 192.168.x.x:
    • 192.168.255.255

In my case:

var udpPort = new osc.UDPPort({
  localAddress: "0.0.0.0",
  localPort: 57121,
  metadata: true,
  broadcast: true
});

udpPort.open();

udpPort.on("ready", function () {
  udpPort.send({
    address: "/s_new",
    args: [
      {
        type: "s",
        value: "default"
      },
      {
        type: "i",
        value: 100
      }
    ]
  }, "192.168.255.255", 8050);
});