我是 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>
希望有帮助!
关于node.js - 到 'ws://chattestarpit.herokuapp.com/' 的 WebSocket 连接失败 : Error during WebSocket handshake: Unexpected response code: 503,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48477499/