首页 > 代码库 > [原]pomelo基础知识(一)
[原]pomelo基础知识(一)
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)))
实验结果:
[原]pomelo基础知识(一)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。