如何解决无法让我的 WebSocket 在 Plesk 服务器上的 NodeJS 中运行?
我正在尝试使用 Node.js、Express.js 和 Socket.IO 部署一个小型协作绘图应用程序。
本地它在运行 Node.js 的 MacOS 上完美运行,通过 LAN 和 WAN,但我无法让它在我们的 Plesk 服务器上运行。我已按照 Alexei Yuzhakov 的指南在 Plesk 中安装和配置 Node.js:
https://www.plesk.com/blog/product-technology/node-js-plesk-onyx/
我还使用了一些 Node.js 测试应用程序,一切似乎都已配置并正常工作。
然后我安装了我的应用程序并运行 NPM 安装以成功下载依赖项。
但是,当客户端尝试连接时,会出现以下错误:
加载资源失败:请求超时。 http://example.com:3000/socket.io/?EIO=3&transport=polling&t=NWEYhCy
不知何故,客户端无法连接到端口 3000 上的套接字
我尝试了各种方法,例如禁用 PHP,我还删除了 Apache 设置中的代理模式设置复选框。但没有运气。
任何帮助将不胜感激!
服务器代码(server.js):
library(XML)
#Parsing this way works fine
hpx <- xmlRoot(xmlTreeParse("My Design.xml"))
hpx[[1]][[2]]
#But this way returns empty lists
hpx2 <- xmlInternalTreeParse("My Design.xml")
getNodeSet(hpx2,"/HPXML/XMLTransactionHeaderInformation/XMLGeneratedBy")
客户代码:
// Using express: http://expressjs.com/
var express = require('express');
// Create the app
var app = express();
// Set up the server
var server = app.listen(3000,listen);
// This call back just tells us that the server has started
function listen() {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://' + host + ':' + port);
}
app.use(express.static('public'));
// WebSocket Portion
// WebSockets work with the HTTP server
var io = require('socket.io')(server);
// Register a callback function to run when we have an individual connection
// This is run for each individual user that connects
io.sockets.on('connection',// We are given a websocket object in our function
function (socket) {
console.log("We have a new client: " + socket.id);
// When this user emits,client side: socket.emit('otherevent',some data);
socket.on('mouse',function(data) {
// Data comes in as whatever was sent,including objects
console.log("Received: 'mouse' " + data.x + " " + data.y);
// Send it to all other clients
socket.broadcast.emit('mouse',data);
// This is a way to send to everyone including sender
// io.sockets.emit('message',"this goes to everyone");
}
);
socket.on('disconnect',function() {
console.log("Client has disconnected");
});
}
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。