简体   繁体   English

客户端无法连接到托管在 Azure 应用程序服务上的 nodejs websocket 服务器?

[英]Client ws can't connect to nodejs websocket server hosted on Azure app service?

Anybody knows how to setup a websocket server nodejs (npm package ws) app service on Azure?有人知道如何在 Azure 上设置 websocket 服务器 nodejs (npm package ws) 应用程序服务吗? My ws client can't connect to the ws server... Thank you for any hint!我的 ws 客户端无法连接到 ws 服务器...感谢您的任何提示!

Azure 应用服务屏幕截图

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.

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