[英]Client ws can't connect to nodejs websocket server hosted on Azure app service?
Seems you missed something to start up your application.似乎您错过了启动应用程序的内容。 I write a sample demo for you,the project secture is simple just like below:
我给你写了一个示例演示,项目部分很简单,如下所示:
Code of wstest.js
: wstest.js
的代码:
const WebSocket = require('ws');
const port = process.env.PORT || 8080
const wss = new WebSocket.Server({ port });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.send('something from server');
});
I use vs code to deploy this project directly, so that this project will under folder: /home/site/wwwroot/
so we should use node command to start up it, just as below:我直接用vs code部署这个项目,这样这个项目就会在文件夹:
/home/site/wwwroot/
下,所以我们要用node命令来启动它,如下图:
After deploying it, let's test it from local:部署好后,我们在本地测试一下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.