1234567891011121314151617181920212223242526272829303132 |
- local osc = require("osc")
- local socket = require("socket")
- local routing = require("routing")
- return function(host, port, sendPorts)
- -- server setup
- print("Binding to host '" .. host .. "' and port " .. port .. "...")
- local udp = assert(socket.udp())
- assert(udp:setsockname(host, port))
- assert(udp:settimeout(.01))
- local ip, boundPort = udp:getsockname()
- assert(ip, boundPort)
- print("Waiting packets on " .. ip .. ":" .. port .. "...")
- coroutine.yield()
- -- server loop
- while true do
- local dgram = udp:receivefrom()
- if dgram then
- local incoming = osc.unpack(dgram)
- local outgoings = routing.createRoutedMessages(incoming)
- for _, out in pairs(outgoings) do
- for _, sp in pairs(sendPorts) do
- udp:sendto(osc.pack(out),"127.0.0.1",sp)
- end
- end
- end
- coroutine.yield()
- end
- end
|