node.js - 到 'ws://chattestarpit.herokuapp.com/' 的 WebSocket 连接失败 : Error during WebSocket handshake: Unexpected response code: 503

标签 node.js heroku websocket

我是 WebSocket (webRTC) 的新手。我创建了一个视频聊天应用程序。它在本地主机上工作。

服务器

    app.listen(process.env.PORT || 8081, function () {  
   console.log("Example app listening at 8081" )
});
app.get('/', function(req, res){
    res.sendfile('index.html');
});
//require our websocket library 
var WebSocketServer = require('ws').Server; 

//creating a websocket server at port 9090 
var wss = new WebSocketServer({server: app}); 

//all connected to the server users 
var users = {};

客户
//connecting to our signaling server
var HOST = location.origin.replace(/^http/, 'ws');
var conn = new WebSocket(HOST);

conn.onopen = function () { 
   console.log("Connected to the signaling server"); 
};

Heroku 显示 WebSocket 存在一些问题。提前致谢。

最佳答案

实际上,如果您看到“heroku 日志”,那么您会发现运行应用程序的端口是一个随机的 5 位数字。 (如 28896、53365 等)它实际上从未在下半年运行 || 8081。

您需要调试实际的根本原因,您可以做的是

  • 在您的应用程序文件夹中打开终端
  • 输入命令 heroku logs -t --app <your-app-name>
  • 它将提供所有日志,包括基于 nodejs 的控制台
  • 基于该应用相应的修复

  • 希望有帮助!

    关于node.js - 到 'ws://chattestarpit.herokuapp.com/' 的 WebSocket 连接失败 : Error during WebSocket handshake: Unexpected response code: 503,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48477499/

    相关文章:

    ios - WebSocket网络错误: The operation couldn’t be completed

    javascript - 不能在 AppFog Node App 上包含脚本/css

    node.js - 使用 Handlebars.js 将一个 html 文件包含到另一个 html 文件中

    javascript - Sequelize hasMany 关系的 getAssociation

    kubernetes - Kubernetes 上的 Socket.io 入口 Controller (无法建立连接)

    java - 通过 Websocket Controller 打印从 Stomp 传入的 json 数组

    javascript - 获取 Puppeteer 中 XPath 的所有链接(暂停或不起作用)?

    django - Heroku 和 Django 连接池

    javascript - 部署到 Heroku 时异步功能不起作用

    java - Heroku 在 Java REST API 应用程序启动期间说 "Process exited with status 0"