pomelo
pomelo copied to clipboard
需要怎么设置,才能接收https的websoket数据包,支持https吗?
由于项目前端上的是Facebook Instant Games,要求是https的websoket通信,正常服务器接收的包是 msg: {"id":4,"type":0,"compressRoute":1,"route":"gameserver.loginHandler.regist","body":{"channel":"facebook","uid":"eeee","pwd":"pwaeee"},"compressGzip":0}
而布属到facebook上之后,服务器收到的包就变成了 message is {"type":"Buffer","data":[22,3,1,2,0,1,0,1,252,3,3,190,36,124,87,46,163,17,57,120,54,155,140,179,110,113,158,6,109,3,111,137,104,60,92,125,195,221,117,77,183,4,58,32,46,190,61,106,1,232,165,79,250,224,63,156,37,228,242,59,178,208,247,229,150,169,40,51,116,24,170,101,182,185,73,48,0,34,202,202,19,1,19,2,19,3,192,43,192,47,192,44,192,48,204,169,204,168]}这种格式。
pomelo服务器需要怎么设置,或者是不支持,还是我理解有误?忘大神们指点一二。
官方的wiki有关于https支持的文章
这个是因为客服端用https请求吗?
----- app.js 里直接增加就行了
app.configure('production|development', 'gate|connector',function() { app.set('connectorConfig', { connector : pomelo.connectors.hybridconnector, transports: appCfg.connectorConfig.transports, disconnectOnTimeout:true, heartbeat : appCfg.connectorConfig.heartbeat, timeout : appCfg.connectorConfig.timeout, ssl: { /// 这里就是 配置 type: 'wss', key: fs.readFileSync('./keys/server.key'), cert: fs.readFileSync('./keys/server.crt'), } // enable useProto //,useProtobuf: true }); ........ });
nginx转一下最方便
----- app.js 里直接增加就行了
app.configure('production|development', 'gate|connector',function() { app.set('connectorConfig', { connector : pomelo.connectors.hybridconnector, transports: appCfg.connectorConfig.transports, disconnectOnTimeout:true, heartbeat : appCfg.connectorConfig.heartbeat, timeout : appCfg.connectorConfig.timeout, ssl: { /// 这里就是 配置 type: 'wss', key: fs.readFileSync('./keys/server.key'), cert: fs.readFileSync('./keys/server.crt'), } // enable useProto //,useProtobuf: true }); ........ });
谢谢,之前就已经解决啦。
nginx转一下最方便
嗯嗯,本身是支持的,已经解决了,我之前理解错误了。
服务器这样配置 app.configure('production|development', 'gameserver', function(){ app.set('connectorConfig', { connector : pomelo.connectors.hybridconnector, heartbeat : 20, useDict : true, useProtobuf: true,
ssl: {
type: 'wss',
key: fs.readFileSync(path.join(configpath, './key/privkey.pem')),
cert: fs.readFileSync(path.join(configpath, './key/cert.pem')),
}
});
});
客户端的连接ws改成wss就行 pomelo.init = function (params, cb) { this.initCallback = cb; var host = params.host; var port = params.port; var url = "wss://"; if (host) { url += host; } if (port) { url += ':' + port; }
this.handshakeBuffer.user = params.user;
this.handshakeCallback = params.handshakeCallback;
this.initWebSocket(url, cb);
};
PS: 因为访问之前需要请求一次https://127.0.0.1:port,这样获取访问权限,可以用代码去请求一次。 微信小程序不充许出现端口,可以直接把端口改成默认端口443(鄙视鹅厂)。
当然以上一切的一切,nginx可以很方便解决。