zoukankan      html  css  js  c++  java
  • [原]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)))

    实验结果:

  • 相关阅读:
    [读书计划]2015读书计划
    [整理]iOS开发学习
    nginx配置
    Nginx的使用
    Spring
    JSP的使用以及EL和JSTL的使用
    关于linux安装tomcat和mysql
    linux常用操作(安装jdk配置环境变量)
    redis的安装与使用
    Mybatis
  • 原文地址:https://www.cnblogs.com/U-tansuo/p/pomelo_gate_server.html
Copyright © 2011-2022 走看看