【问题标题】:sending OSC between machines on a LAN using Node.js and OSC.js使用 Node.js 和 OSC.js 在 LAN 上的机器之间发送 OSC
【发布时间】: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)

【问题讨论】:

    标签: node.js lan osc


    【解决方案1】:

    问题是您用来发送 OSC 消息的osc.UDPPort 将其localAddress 绑定到环回地址,该地址仅限于本地计算机内的连接。结果,您的发件人找不到您的收件人。

    解决方案是将发件人的localAddress 绑定到适当的网络接口。如果您的 192.168.0.5 IP 地址稳定,并且当您将笔记本电脑连接到另一个网络(例如,用于演出或画廊安装)时,您无需担心它会发生变化,那么您可以使用它。否则,您可能需要使用 mDNS 名称(“foo.local”)或“所有接口”地址 0.0.0.0。

    当我在我的网络上尝试时,对“发件人代码”的这种更改对我有用:

    var osc = require("osc");
    
    var udp = new osc.UDPPort({
        localAddress: "0.0.0.0", // Totally does matter here :)
        localPort: 5000,
        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);
    });
    

    附带说明一下,osc.js 的行为确实不同于常规的 Node.js UDP 套接字,因为如果省略本地地址,Node 将默认为 0.0.0.0。但是,如果省略了 localAddressosc.UDPPort 将始终绑定到 127.0.0.1(在最初实现 osc.js 时,这对我来说似乎更安全一些,但我可以看到它可能会令人困惑)。

    这个问题也是discussed on the osc.js issue tracker,我会更新文档以防止你在这里遇到的那种混乱。祝你的项目好运!

    【讨论】:

    • 不幸的是,我花了 4 天时间寻找这个,它一直盯着我的 UDPPort 本地地址。谢谢科林。这解决了它!
    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 2018-03-31
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 2019-02-22
    • 2021-11-19
    • 1970-01-01
    相关资源
    最近更新 更多