This trivial example shows how to open a connection to Hz's builtin OSC server and wait for OSC traffic to be delivered. Here, we expect OSC traffic to originate from an external source (which could be a separate instance of Hz running on your LAN). Here we simply print out the OSC traffic which is a great way to learn about OSC or to better understand behavior of your OSC provider.
For more on Hz's OSC support including a discussion on hostnames and port numbers, see here.
oscin.js
let oin = new OSCIn();
let err = await oin.Connect(); // listen on default port (22000)
if(!err)
{
console.info("oin connected");
for(let i=0;i<30;i++)
{
let msg = await oin.Recv();
// msg.addr contains the target address, eg "/foo/note"
// msg.types describes the datatype associated with elements
// in msg.data[]. "if": means the first element is an integer
// and the second is a float.
// msg.data is a mixed-type array of elements.
console.log(`${i} OSC msg: ` + JSON.stringify(msg));
}
console.info("oin done after 30 messages");
oin.Disconnect();
}
else
console.warn("Problem listening on default OSC port.");