我有一个运行在高山linux docker映像上的socket.io服务器。我可以通过html客户端连接到端口8080上的套接字,但是如果我的Android或iOS应用尝试尝试连接,则握手失败。
我读到一些有关linux的内容,它自动允许到/ node的代理连接,但是/ socket代理必须以特殊方式设置。可能是反向代理?我在AWS EC2 ubuntu经典实例上运行了同一台服务器,并且运行良好。
这是.conf文件
[supervisord]
nodaemon=true
[program:websocket]
command=/usr/bin/node /srv/app.js
autostart=true
autorestart=true
startretries=3
stderr_logfile=/srv/logs/websocket.err.log
stdout_logfile=/srv/logs/websocket.out.log
服务器:
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.sockets.on('connection', function (socket) {
socket.on('join_channel', function(channel){
log_me("join_channel: " + channel);
socket.channel = channel;
socket.join(channel);
});
// kue
socket.on('proceed', function(channel, data){
log_me("proceed: " + channel + " - " + data);
io.sockets.in(channel).emit('proceed', data);
});
// kue
socket.on('instruct', function(channel, data){
log_me("instruct: " + channel + " - " + data);
io.sockets.in(channel).emit('instruct', data);
});
// driver app
socket.on('status_update', function(channel, data){
log_me("status_update: " + channel + " - " + data);
io.sockets.in(channel).emit('status_update', data);
});
// driver app
socket.on('status_update2', function(data){
var obj = JSON.parse(data);
log_me("status_update: " + obj.channel + " - " + data);
io.sockets.in(obj.channel).emit('status_update', data);
});
// requester and driver app
socket.on('video_call_response', function(data){
var obj = JSON.parse(data);
log_me("video_call_response: " + obj.channel + " - " + data);
io.sockets.in(obj.channel).emit('video_call_response', data);
});
// requester and driver app
socket.on('video_call_hangup', function(data){
var obj = JSON.parse(data);
log_me("video_call_hangup: " + obj.channel + " - " + data);
io.sockets.in(obj.channel).emit('video_call_hangup', data);
});
// requeter and driver app
socket.on('request_video_call', function(data){
var obj = JSON.parse(data);
log_me("request_video_call: " + obj.channel + " - " + data);
io.sockets.in(obj.channel).emit('request_video_call', data);
});
// anything that disconnects
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 = {'ambulance_id' : c, 'status' : 'DISCONNECTED'}
io.sockets.in(c).emit('status_update', JSON.stringify(data));
}
}
socket.leave(socket.channel);
});
});