简体   繁体   English

Node.js HTTP请求发送OSC消息

[英]Node.js HTTP Request to send OSC message

I am new to Node.js and am wondering if anyone has an idea on how I'd go about making a program that sends an OSC message when someone makes an HTTP request to my server? 我是Node.js的新手,并且想知道是否有人对如何制作一个在有人向我的服务器发出HTTP请求时发送OSC消息的程序有想法?

I have a simple program running right now that when you run it it sends an OSC message, how might I expand it so this message gets sent anytime a certain HTTP request is made? 我现在有一个运行的简单程序,当您运行它时,它会发送一条OSC消息,我该如何扩展它,以便在发出某个HTTP请求时随时发送此消息?

var osc = require('node-osc');

var client = new osc.Client('127.0.0.1', 3333);
client.send('/1', 1);

Thanks 谢谢

To receive HTTP requests, you need an HTTP server. 要接收HTTP请求,您需要一个HTTP服务器。 Node has a built-in HTTP server. 节点具有内置的HTTP服务器。 To handle simple routing, I usually go straight for Express which sets up a nice middleware stack and some other helpful bits as you build out your application. 为了处理简单的路由,我通常会直接使用Express,它会在构建应用程序时建立一个不错的中间件堆栈和一些其他有用的功能。 From the documentation: 从文档中:

var express = require('express');
var app = express();

app.get('/', function(req, res){
  res.send('hello world');
});

app.listen(3000);

Now, what I would do is set up a specific endpoint for OSC messages: 现在,我要做的是为OSC消息设置一个特定的端点:

app.all('/osc', functin (req, res) {
   oscClient.send('/1', 1);
}

You can add parameters and what not if you want Express to handle that for you in the URL, or you can get at the query string or POST data directly from the req object. 您可以添加参数,如果不希望Express通过URL为您处理,则可以添加参数,或者可以直接从req对象获取查询字符串或POST数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM