-
-
Notifications
You must be signed in to change notification settings - Fork 232
/
listener.js
39 lines (27 loc) · 903 Bytes
/
listener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const IP_ADDR = '127.0.0.1'
const UDP_PORT = 49161
const OSC_PORT = 49162
const dgram = require('dgram')
const udpserver = dgram.createSocket('udp4')
const osc = require('./desktop/node_modules/node-osc')
const oscserver = new osc.Server(OSC_PORT, IP_ADDR)
console.log(`Started Listener\n\nUDP:${UDP_PORT}\nOSC:${OSC_PORT}\n`)
// Error
udpserver.on('error', (err) => {
console.log(`UDP server:\n${err.stack}`)
udpserver.close()
})
oscserver.on('error', (err) => {
console.log(`OSC server:\n${err.stack}`)
oscserver.close()
})
// Message
udpserver.on('message', (msg, rinfo) => {
console.log(`UDP server: ${msg} from ${rinfo.address}:${rinfo.port}`)
})
oscserver.on('message', (msg, rinfo) => {
console.log(`OSC server: ${msg} from ${rinfo.address}:${rinfo.port} at ${msg[0]}`)
})
udpserver.bind(UDP_PORT)
// Send a run message to orca
udpserver.send('run', 0, 3, 49160, IP_ADDR)