标签:style blog http io color os ar for sp
1.pomelo基本介绍 http://blog.gfdsa.net/2013/06/04/pomelo/pomelo_study_two/
2.如何配置一个gate服务器
(1)首先 需要在gameserver下的 app.js添加如下代码
app.configure(‘production|development‘, ‘gate‘, function(){
app.set(‘connectorConfig‘,
{
connector : pomelo.connectors.hybridconnector,
});
});
(2)在gameserver下的config的server.json 和adminServer.json 配置如下:
server.json
adminServer.json
(3)在gameserver的app/servers新建gate/handler/gateHandler.js 代码可以抄connector/handler/entryHandler.js
module.exports = function(app) { return new Handler(app); }; var Handler = function(app) { this.app = app; }; /** * New client entry. * * @param {Object} msg request message * @param {Object} session current session object * @param {Function} next next step callback * @return {Void} */ Handler.prototype.entry = function(msg, session, next) { var res = this.app.getServersByType(‘connector‘); //获得connector类型服务器 返回值为connector类型服务器的数组 console.log(res[0].clientPort) next(null, {code: 200,host: res[0].host,port: res[0].clientPort});//取第一个connector类型服务器的ip和端口 }; /** * Publish route for mqtt connector. * * @param {Object} msg request message * @param {Object} session current session object * @param {Function} next next step callback * @return {Void} */ Handler.prototype.publish = function(msg, session, next) { var result = { topic: ‘publish‘, payload: JSON.stringify({code: 200, msg: ‘publish message is ok.‘}) }; next(null, result); }; /** * Subscribe route for mqtt connector. * * @param {Object} msg request message * @param {Object} session current session object * @param {Function} next next step callback * @return {Void} */ Handler.prototype.subscribe = function(msg, session, next) { var result = { topic: ‘subscribe‘, payload: JSON.stringify({code: 200, msg: ‘subscribe message is ok.‘}) }; next(null, result); };
(4)客户端请求:(我是用quick实现的,根据自己需要 只要路由发“gate.gateHandler.entry”就行)
local route = "gate.gateHandler.entry"
local msg = { uid = "luaClientWindows" }
client:pomeloRequest(route,tostring(json.encode(msg)))
实验结果:
标签:style blog http io color os ar for sp
原文地址:http://www.cnblogs.com/U-tansuo/p/pomelo_gate_server.html