• [原]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)))

    实验结果:

  • 相关阅读:
    (转)如何最佳地使用memcached?
    win7 安装 memcached
    (转)怎么把主机的文件复制到虚拟机上
    memcache和redis本质区别在哪里?
    关于memcached
    (转)memcached注意事项
    (转)Memcached深度分析
    《项目架构那点儿事》——快速构建Junit用例
    《项目架构那点儿事》——工具类,你喜欢你就拿去
    《项目架构那点儿事》——Hibernate泛型Dao,让持久层简洁起来
  • 原文地址:https://www.cnblogs.com/U-tansuo/p/pomelo_gate_server.html
Copyright © 2020-2023  润新知