为什么我从服务器收到以下错误?在socket.io上,何时可以通过浏览器访问socket.io?
无法加载资源:无法连接到服务器。
您可以访问该站点,然后socket.io打招呼。
http://produ-Publi-18S2BX3E0BF4K-2059687405.us-west-2.elb.amazonaws.com
当我的应用尝试访问它时,我加载失败
http://produ-publi-18s2bx3e0bf4k-2059687405.us-west-2.elb.amazonaws.com:8080/socket.io/1/?t=1558154228361
服务器:
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str){
return this.slice(0, str.length) == str;
};
}
function log_me(msg){
var ts = new Date(new Date().getTime() - (3600000*4));
var tss = ts.toString();
tss = tss.substring(0, tss.indexOf(' GMT'));
console.log(tss + ": " + msg);
}
var io = require('socket.io').listen(8080);
io.set('log level', 2);
io.set('transports', ['flashsocket']);
io.set('origins', '*:*');
io.sockets.on('connection', function (socket) {
socket.on('join_channel', function(channel){
log_me("join_channel: " + channel);
socket.channel = channel;
socket.join(channel);
});
socket.on('proceed', function(channel, data){
log_me("proceed: " + channel + " - " + data);
io.sockets.in(channel).emit('proceed', data);
});
socket.on('instruct', function(channel, data){
log_me("instruct: " + channel + " - " + data);
io.sockets.in(channel).emit('instruct', data);
});
socket.on('status_update', function(channel, data){
log_me("status_update: " + channel + " - " + data);
io.sockets.in(channel).emit('status_update', data);
});
socket.on('ambulance_move', function(channel, data){
io.sockets.in(channel).emit('ambulance_move', data);
});
socket.on('disconnect', function(){
log_me("disconnect: " + socket.channel);
if(socket.channel){
if(socket.channel.startsWith("a_")){
var c = socket.channel.replace("a_", "");
var data = {'amb_id' : c, 'status' : 'DISCONNECTED'}
io.sockets.in(c).emit('status_update', JSON.stringify(data));
}
}
socket.leave(socket.channel);
});
});