【发布时间】:2017-03-18 16:19:32
【问题描述】:
是否有人创建了一个工作设置,其中 OSC 使用 Node.js 在 LAN 上的机器之间发送?理想情况下,使用 Colin Clark 的 osc.js 包?
我认为应该是一个非常简单的示例,但它不起作用 - 我收到 EADDRNOTAVAIL 错误,这意味着远程地址不可用。但是,我可以成功地ping 另一台笔记本电脑。
这是代码和错误,供参考:
发送代码(笔记本电脑在 192.168.0.5):
var osc = require("osc");
var udp = new osc.UDPPort({
localAddress: "127.0.0.1", // shouldn't matter here
localPort: 5000, // not receiving, but here's a port anyway
remoteAddress: "192.168.0.7", // the other laptop
remotePort: 9999 // the port to send to
});
udp.open();
udp.on("ready", function () {
console.log("ready");
setInterval(function () {
udp.send({
address: "/sending/every/second",
args: [1, 2, 3]
})
}, 1000);
});
接收代码(笔记本电脑上的 192.168.0.7):
var osc = require("osc");
var udp = new osc.UDPPort({
localAddress: "192.168.0.7",
localPort: 9999
});
udp.open();
udp.on("ready", function () {
console.log("receiver is ready");
});
udp.on("message", function(message, timetag, info) {
console.log(message);
});
这是我在运行发送代码时遇到的错误:
ready
events.js:141
throw er; // Unhandled 'error' event
^
Error: send EADDRNOTAVAIL 192.168.0.7:9999
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at SendWrap.afterSend [as oncomplete] (dgram.js:345:11)
【问题讨论】: