[英]Node.js REST with Sockets
The problem I am trying to solve is我试图解决的问题是
I can communicate to the client via REST and separately I can communicate to the external server via socket (response time is ~100ms).我可以通过 REST 与客户端通信,另外我可以通过套接字与外部服务器通信(响应时间约为 100 毫秒)。 But combining these results yields nothing.
但是将这些结果结合起来却一无所获。
const sjsc = require('sockjs-client');
app.post('/form', function(req, res) {
const srvc = sjsc('http://external.server:port/path');
srvc.onopen = function () {
srvc.send(testData);
}
srvc.onmessage = function(data) {
console.log('received ', data);
res.send(data);
};
});
const srvc = sjsc('http://external.server:port/path');
this needed to be a let
.这需要是一个
let
。 this is the only thing i changed and works perfectly.这是我唯一改变并且完美运行的东西。
let srvc = sjsc('http://external.server:port/path');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.