将我的代码服务器升级到Heroku时遇到问题。没有套接字连接消息。 这是Heroku上服务器端的代码
var appS = require('express')();
var http = require('http').Server(appS);
var io = require('socket.io')(http,{path: '/octagon/socket.io'});
http.listen(3000, function(){
console.log('listening on *:3000');
});
io.sockets.on('connection', function (socket) {
socket.on('test',function (message) {
console.log(message)
})
})
这是客户端的代码
var socket = io.connect('https://murmuring-waters-83521.herokuapp.com/',
{
reconnect: true,
transports : ['websocket'],
ressources: '/octagon/socket.io'
});
我仍然收到此消息
WebSocket connection to 'wss://murmuring-waters-83521.herokuapp.com/octagon/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 503
答案 0 :(得分:1)
您可以通过更新客户端配置来使其工作
var socket = io('//murmuring-waters-83521.herokuapp.com',
{
reconnect: true,
rejectUnauthorized: false, // new
path: '/octagon/socket.io' // use this instead of `ressources`
});
socket.on('connection', function () {
alert('Browser is connected to server!');
});