OSC outIp - formatting the IP for a network range (multiple destinations)

Hi,

I would like to send OSC messages to multiple computers on the same private network.

The network devices will have fixed IP addresses using a 192.168.0.0/24 network and I can send OSC messages to a single IP address using the following string:

IPAddress outIp(192, 168, 1, 64);

However I can't work out if I can change the outIp to a network range? Something like the following I guess but this is not working:

IPAddress outIp(192, 168, 1, 0/24);

Thanks,

Michael.

You would probably just need to iterate through all the IP addresses you want to send messages to:

IPAddress outIp(192, 168, 1, 0);
for (int octet = 0; octet <= 255; ++octet) {
  outIp[3] = octet;
  // send to outIp
}

That assumes you actually want to send to all 256 IP addresses.

Good idea, didn’t think of that and easy to restrict to a short range, will give it a test. Thanks.

pert:
You would probably just need to iterate through all the IP addresses you want to send messages to:

IPAddress outIp(192, 168, 1, 0);

for (int octet = 0; octet <= 255; ++octet) {
  outIp[3] = octet;
  // send to outIp
}



That assumes you actually want to send to all 256 IP addresses.

@pert - I would send the OSC message to a fixed number of computers to share sensor and random data, most likely 2-3 but I guess could be more but not the whole network :slight_smile:

You could also put the specific IP addresses in an array, then use a for loop to iterate through the elements of the array:

const IPAddress outIp[] = {IPAddress(192, 168, 1, 0), IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 2)};
for (byte ipCounter = 0; ipCounter < sizeof(outIp) / sizeof(outIp[0]); ++ipCounter) {
  // send to outIp[ipCounter]
}

A bit of research shows OSC uses UDP protocol. You might try a broadcast.

IPAddress outIp(192, 168, 1, 255);