コード例 #1
0
ファイル: NetMgr.cs プロジェクト: isoundy000/shmj3d
    public void Login(string account, string token)
    {
        int port = 5005;

        mAccount = account;
        mToken   = token;

        Debug.Log("Login");

        pc.initClient(mServer, port, ret => {
            if (!ret)
            {
                Debug.Log("Login initClient fail");
                GameAlert.Show("连接服务器失败,请检查网络");
                return;
            }

            pc.connect(null, data => {
                JsonObject msg = new JsonObject();
                msg ["uid"]    = account;

                pc.request("gate.gateHandler.queryEntry", msg, OnQuery);
            });
        });
    }
コード例 #2
0
    void OnQuery(JsonObject result)
    {
        if (Convert.ToInt32(result["code"]) == 200)
        {
            pomeloClient.disconnect();

            string connectorHost = (string)result["host"];
            int    connectorPort = Convert.ToInt32(result["port"]);

            pomeloClient = new PomeloClient();

            pomeloClient.initClient(connectorHost, connectorPort, () =>
            {
                //The user data is the handshake user params
                JsonObject user = new JsonObject();
                pomeloClient.connect(user, data =>
                {
                    Entry();
                });
            });

            // 请求到了connector数据后,跳转场景
            //_bNeedLoadScene = true;
        }
    }
コード例 #3
0
    //Login the chat application and new PomeloClient.
    void Login()
    {
        string host = "127.0.0.1";
        int    port = 33014;

        pc = new PomeloClient();

        pc.NetWorkStateChangedEvent += (state) =>
        {
            Debug.Log("NetWorkStateChangedEvent: " + state);
        };

        Debug.Log("Connecting to gate server: " + host + ":" + port);

        pc.initClient(host, port, () => {
            Debug.Log("pc.initClient callback.");


            pc.connect((data) => {
                Debug.Log("pc.connect callback.");
                JsonObject msg = new JsonObject();
                msg["uid"]     = userName;
                pc.request("gate.gateHandler.queryEntry", msg, OnQuery);
                //pc.request("gate.gateHandler.queryEntry", msg, (response) => {
                //    Debug.Log("callback here!");
                //});
            });
        });
    }
コード例 #4
0
    //Login the chat application and new PomeloClient.
    void Login()
    {
        //string host = "120.27.163.31";
        string host = "127.0.0.1";
        int    port = 3014;

        pomeloClient = new PomeloClient();

        //listen on network state changed event
        pomeloClient.NetWorkStateChangedEvent += (state) =>
        {
            Debug.logger.Log("CurrentState is:" + state);
        };

        pomeloClient.initClient(host, port, () =>
        {
            //The user data is the handshake user params
            JsonObject user = new JsonObject();
            //user["uid"] = userName;
            pomeloClient.connect(user, data =>
            {
                //process handshake call back data
                JsonObject msg = new JsonObject();
                msg["uid"]     = userName;
                pomeloClient.request("gate.gateHandler.queryEntry", msg, OnQuery);
            });
        });
    }
コード例 #5
0
ファイル: ConnectionManager.cs プロジェクト: PenpenLi/Nav
    /// <summary>
    /// 与服务器器建立连接
    /// </summary>
    /// <param name="conResult">Con result.</param>
    public void Connect(Action <bool> conResult)
    {
        connectResultCallback = conResult;
        if (pclient != null && conResult != null)
        {
            Debug.Log("(pclient != null && conResult != null)");
            InvokeConnectResult(true);
            return;
        }

        ChangeConnectStatus(ConnectStatus.CONNECTING);
        EventDispatcher.Instance().RegistEventListener(NetDataRequestTip.NET_REQUEST_START, NetDataRequestTip.startReq);
        EventDispatcher.Instance().RegistEventListener(NetDataRequestTip.NET_REQUEST_END, NetDataRequestTip.endReq);
        EventDispatcher.Instance().RegistEventListener(NetDataRequestTip.NET_CONNECT_CLOSE, NetDataRequestTip.ConnectClose);
        EventDispatcher.Instance().DispatchEvent(NetDataRequestTip.NET_REQUEST_START, null);

        pclient = new PomeloClient();
        pclient.NetWorkStateChangedEvent += OnGateServerNetWorkStateChange;
        try{
            pclient.initClient(CGNetConst.HOST, CGNetConst.POST, () => {
                pclient.connect(null, conData1 => {
                    Debug.Log("Gate服务器连接成功!");
                    pclient.request(CGNetConst.ROUTE_LOGIN, delegate(JsonObject jsonObject) {
                        Debug.Log("PARA_CODE = " + jsonObject [CGNetConst.PARA_CODE]);
                        if (Convert.ToInt32(jsonObject [CGNetConst.PARA_CODE]) == CGNetConst.RESULT_CODE_SUC)
                        {
                            Disconnect(true);
                            Debug.Log("与Gate服务器断开连接,准备连接游戏服务器……");
                            Debug.Log("host=" + (string)jsonObject [CGNetConst.PARA_HOST] + "   port=" + jsonObject [CGNetConst.PARA_PORT]);
                            pclient = new PomeloClient();
                            pclient.NetWorkStateChangedEvent += OnNetWorkStateChange;
                            pclient.initClient((string)jsonObject [CGNetConst.PARA_HOST], Convert.ToInt32(jsonObject [CGNetConst.PARA_PORT]), () => {
                                pclient.connect(null, conData2 => {
                                    ChangeConnectStatus(ConnectStatus.CONNECTED);
                                    Debug.Log("游戏服务器连接成功!");

//                                    if(conResult != null)
//                                    {
//                                        conResult(true);
//                                    }
                                });
                            });
                        }
                        else
                        {
                            Debug.Log("Connect faild!");
                            InvokeConnectResult(false);
//                            if(conResult != null)
//                            {
//                                conResult(false);
//                            }
                        }
                    });
                });
            });
        }catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
    }
コード例 #6
0
        public static void OnQuery(JsonObject result)
        {
            if (Convert.ToInt32(result["code"]) == 200)
            {
                pc.disconnect();

                string host = (string)result["host"];
                int port = Convert.ToInt32(result["port"]);
                pc = new PomeloClient();

                pc.NetWorkStateChangedEvent += (state) =>
                {
                    Console.WriteLine(state);
                };

                pc.initClient(host, port, () =>
                {
                    pc.connect(null, (data) =>
                    {
                        JsonObject userMessage = new JsonObject();
                        Console.WriteLine("on connect to connector!");

                        //Login
                        JsonObject msg = new JsonObject();
                        msg["username"] = "******";
                        msg["rid"] = "pomelo";

                        pc.request("connector.entryHandler.enter", msg, OnEnter);
                    });
                });
            }
        }
コード例 #7
0
 /// <summary>
 /// connect to server and response
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="port"></param>
 /// <param name="user">handshake msg for connect</param>
 /// <param name="action">default request callback</param>
 public void Connect(string ip, int port, JsonObject user, Action <JsonObject> action)
 {
     if (m_Conn != null)
     {
         Debug.Log("the network has been connected!");
         return;
     }
     Debug.Log("connect to ip: " + ip + " port: " + port);
     m_Conn = new PomeloClient();
     m_Conn.NetWorkStateChangedEvent += (state) =>
     {
         Debug.Log("network state: " + state);
         if (NetState != null)
         {
             NetState.Invoke(state);
         }
     };
     m_Conn.initClient(ip, port, () =>
     {
         m_Conn.connect(user, (rt) =>
         {
             Dispatcher.Current.BeginInvoke(() =>
             {
                 action.Invoke(rt);
             });
         });
     });
 }
コード例 #8
0
    //Login the chat application and new PomeloClient.
    void Login()
    {
        userName = infield_username.text; // 获取输入框中的信息

        if (userName == "")
        {
            return;
        }

        string host = "127.0.0.1"; // gate的host和port
        int    port = 3014;

        pomeloClient = new PomeloClient();

        //listen on network state changed event
        pomeloClient.NetWorkStateChangedEvent += (state) =>
        {
            Debug.logger.Log("CurrentState is:" + state);
        };

        // 请求gate服务器,得到connector服务器的host和clientPort
        pomeloClient.initClient(host, port, () =>
        {
            // user 消息传递给 gate.gateHandler.queryEntry
            JsonObject user = new JsonObject();
            user["uid"]     = userName;
            pomeloClient.connect(user, data =>
            {
                //process handshake call back data
                JsonObject msg = new JsonObject();
                msg["uid"]     = userName;
                pomeloClient.request("gate.gateHandler.queryEntry", msg, OnQuery);
            });
        });
    }
コード例 #9
0
    private void Connect()
    {
        client = new PomeloClient();
        client.initClient(url, port, () =>
        {
            Debug.Log("Pomelo client init success!");
        });

        JsonNode user = new JsonClass();

        user.Add("user", new JsonData("Winddy"));
        user.Add("pwd", new JsonData("123"));

        bool result = client.connect(user, new System.Action <JsonNode>(OnConnection));

        if (result)
        {
            Debug.Log("Connect success!");
        }
        else
        {
            Debug.Log("Connect failed!");
        }

        //ClientTest.loginTest("127.0.0.1", 3014);
    }
コード例 #10
0
ファイル: NetWorkMgr.cs プロジェクト: swiftliang/NewGame
        private IEnumerator _doGetGsInfo(Action <Constants> cb)
        {
            _GateClientConnection.disconnect();

            _gameSvrIP   = null;
            _gameSvrPort = -1;

            Constants code = Constants.INVALID;

            _GateClientConnection.initClient(_loginInfo.gateHost, _loginInfo.gatePort, () =>
            {
                _GateClientConnection.connect(null, (data) =>
                {
                    Debug.Log("connect gate data: " + data);
                    SimpleJson.JsonObject msg = new SimpleJson.JsonObject();
                    msg["uid"] = _loginInfo.uid;
                    //msg["token"] = _loginInfo.token;
                    _GateClientConnection.request(RequestMsg.REQUEST_CONNECTOR, msg, (result) =>
                    {
                        code         = (Constants)Convert.ToInt32(result.data["code"]);
                        _gameSvrIP   = (string)result.data["host"];
                        _gameSvrPort = Convert.ToInt32(result.data["port"]);
                    });
                });
            });

            yield return(new WaitUntil(() => code != Constants.INVALID));

            if (cb != null)
            {
                cb(code);
            }
        }
コード例 #11
0
    void OnQuery(JsonObject result)
    {
        Debug.Log("OnQuery called. Acquired data from gate server.");
        if (Convert.ToInt32(result["code"]) == 200)
        {
            pc.disconnect();

            string host = (string)result["host"];
            int    port = Convert.ToInt32(result["port"]);


            Debug.Log("Connecting to connector server: " + host + ":" + port);
            pc = new PomeloClient();
            pc.initClient(host, port, () => {
                pc.connect((data) =>
                {
                    Entry();
                });
            });
        }
        else
        {
            Debug.Log("Connection error.");
        }
    }
コード例 #12
0
    void Awake()
    {
        callbacks = new Dictionary <string, CbFunc>();
        //初始化 PomeloClient
        client = new PomeloClient();
        client.initClient(host, port, () => {
            client.connect(null, (data) => {
                Debug.Log("connect back data" + data.ToString());
                JsonObject js = new JsonObject();
                js["uid"]     = 12234;
                client.request(router, js, (connectData) =>
                {
                    string conHost = connectData["host"].ToString();
                    int conPort    = int.Parse(connectData["port"].ToString());
                    Debug.Log(conHost + "#" + conPort.ToString());
                    client.disconnect();

                    client = new PomeloClient();
                    client.initClient(conHost, conPort, () =>
                    {
                        client.connect(null, (cb) => {
                        });
                    });
                });
            });
        });
    }
コード例 #13
0
    void OnQuery(JsonObject result)
    {
        if (Convert.ToInt32(result["code"]) == 200)
        {
            pc.disconnect();

            string host = (string)result["host"];
            int    port = Convert.ToInt32(result["port"]);
            pc = new PomeloClient();
            pc.initClient(host, port);
            pc.connect(null, (data) =>
            {
                JsonObject conectorMessage = new JsonObject();
                conectorMessage.Add("deviceId", deviceId);
                pc.request("connector.entryHandler.entry", conectorMessage, (ret) =>
                {
                    if (Convert.ToInt32(ret["code"]) == 200)
                    {
                        isConnected = true;
                        EventsListen();
                        Debug.Log("...... " + data);
                    }
                });
            });
        }
    }
コード例 #14
0
        public static void OnQuery(JsonObject result)
        {
            if (Convert.ToInt32(result["code"]) == 200)
            {
                pc.disconnect();

                string host = (string)result["host"];
                int    port = Convert.ToInt32(result["port"]);
                pc = new PomeloClient();

                pc.NetWorkStateChangedEvent += (state) =>
                {
                    Console.WriteLine(state);
                };

                pc.initClient(host, port, () =>
                {
                    pc.connect(null, (data) =>
                    {
                        JsonObject userMessage = new JsonObject();
                        Console.WriteLine("on connect to connector!");

                        //Login
                        JsonObject msg  = new JsonObject();
                        msg["username"] = "******";
                        msg["rid"]      = "pomelo";

                        pc.request("connector.entryHandler.enter", msg, OnEnter);
                    });
                });
            }
        }
コード例 #15
0
    //建立起一条新的连接
    public void newSocket()
    {
        pclient = new PomeloClient();

        pclient.NetWorkStateChangedEvent += (state) =>
        {
            Debug.Log(state);
            //Console.WriteLine(state);
        };


        pclient.initClient(host, port, () =>
        {
            //The user data is the handshake user params
            JsonObject user = new JsonObject();
            pclient.connect(user, data =>
            {
                ConnectorSender.sendEnter();
                //pclient.request(Routes.CONNECTOR_ENTER, new JsonObject(), OnEnterConnector);
            });

            //把广播事件的名称都注册到pomelo中
            foreach (KeyValuePair <string, Action <JsonObject> > pair in BroadcastFact.callbacks)
            {
                this.registBroadcast(pair.Key);
            }
        });
    }
コード例 #16
0
 public void Connect()
 {
     pc = new PomeloClient();
     pc.initClient(host, port);
     pc.connect(null, (data) => {
         JsonObject msg  = new JsonObject();
         msg["deviceId"] = deviceId;
         msg["id"]       = 1;
         pc.request("gate.gateHandler.queryEntry", msg, OnQuery);
     });
 }
コード例 #17
0
 public static void Init(string host, int port, int uid, Action <JsonObject> act)
 {
     cli = new PomeloClient();
     cli.initClient(host, port, () => {
         cli.connect((hs) => {
             JsonObject msg = new JsonObject();
             msg ["uid"]    = uid;
             cli.request("gate.gateHandler.queryEntry", msg, data => {
                 cli.disconnect();
                 Entry(Convert.ToString(data ["host"]), Convert.ToInt32(data ["port"]), uid, act, data);
             });
         });
     });
 }
コード例 #18
0
    public void Connect(string host, int port, LuaInterface.LuaFunction func)
    {
        pc = new PomeloClient();
        pc.initClient(host, port);
        pc.connect(null, (data) => {
            JsonObject msg  = new JsonObject();
            msg["deviceId"] = deviceId;
            msg["id"]       = 1;
            pc.request("gate.gateHandler.queryEntry", msg, (result) => {
                Debug.Log("--------------------------------------");
                Debug.Log(result.ToString());
                Debug.Log("--------------------------------------");
                if (Convert.ToInt32(result["code"]) == 200)
                {
                    pc.disconnect();

                    string h = (string)result["host"];
                    int p    = Convert.ToInt32(result["port"]);
                    pc       = new PomeloClient();
                    pc.initClient(h, p);
                    pc.connect(null, (dd) =>
                    {
                        JsonObject conectorMessage = new JsonObject();
                        conectorMessage.Add("deviceId", deviceId);
                        pc.request("connector.entryHandler.entry", conectorMessage, (ret) =>
                        {
                            Debug.Log("--------------------------------------");
                            Debug.Log(ret.ToString());
                            Debug.Log("--------------------------------------");
                            if (Convert.ToInt32(ret["code"]) == 200)
                            {
                                isConnected = true;
                                EventsListen();
                            }

                            if (func != null)
                            {
                                PomeloPackage pkg = new PomeloPackage();
                                pkg.luaFunc       = func;
                                pkg.ReturnData    = ret.ToString();
                                Debug.Log("!!!!!!!!!!!!!!!!!!!! " + pkg.ReturnData);
                                AddResultPackage(pkg);
                            }
                        });
                    });
                }
            });
        });
    }
コード例 #19
0
 // Use this for initialization
 void Start()
 {
     //pomeloClient = new PomeloClient(TransportType.TCP);
     pomeloClient = new PomeloClient(TransportType.SSL);
     pomeloClient.NetWorkStateChangedEvent += OnNetWorkStateChange;
     pomeloClient.initClient(gateHost, gatePort, () => {
         JsonObject user = new JsonObject();
         pomeloClient.connect(user, data =>
         {
             JsonObject msg = new JsonObject();
             msg["uid"]     = "hello";
             pomeloClient.request("gate.gateHandler.queryEntry", msg, OnGateQuery);
         });
     });
 }
コード例 #20
0
    public PomeloSocket InitClient(string host, int port, Action <JsonObject> cb)
    {
        Disconnect();
        pclient = new PomeloClient();
        pclient.NetWorkStateChangedEvent += (state) =>
        {
            Debug.Log(state);
        };
        pclient.initClient(host, port, () =>
        {
            Connect(cb);
        });

        pclient.on("websocket-error", (data) =>
        {
            Debug.LogError(data);
        });
        return(this);
    }
コード例 #21
0
ファイル: NetworkClient.cs プロジェクト: zj831007/knight
        public void Connect(string rHost, int rPort, Action OnConnectCompleted = null)
        {
            mClient = new PomeloClient();
            mClient.initClient(rHost, rPort, () =>
            {
                Debug.Log("Pomelo client init success!");

                bool rResult = this.ConnectPomeloServer(OnConnectCompleted);

                if (rResult)
                {
                    Debug.Log("Connect success!");
                }
                else
                {
                    Debug.Log("Connect failed!");
                }
            });
        }
コード例 #22
0
        public static void loginTest(string host, int port)
        {
            pc = new PomeloClient();

            pc.NetWorkStateChangedEvent += (state) =>
            {
                Console.WriteLine(state);
            };

            pc.initClient(host, port, () =>
            {
                pc.connect(null, data =>
                {

                    Console.WriteLine("on data back" + data.ToString());
                    JsonObject msg = new JsonObject();
                    msg["uid"] = 111;
                    pc.request("gate.gateHandler.queryEntry", msg, OnQuery);
                });
            });
        }
コード例 #23
0
    public void connectServer(string host, int port,
                              System.Action <JsonObject> callBack,
                              int connectType = 1)
    {
        if (pclient != null)
        {
            //isShowReConnectPanel = false;
            pclient.NetWorkStateChangedEvent -= NetWorkStateChangedEvent;
            pclient.disconnect();
            pclient = null;
        }

        pclient = new PomeloClient();
        TipManager.instance.showReconnectPanel(0);
        pclient.NetWorkStateChangedEvent += NetWorkStateChangedEvent;

        pclient.initClient(host, port, () =>
        {
            pclient.connect(null, callBack);
        });
    }
コード例 #24
0
ファイル: ClientTest.cs プロジェクト: swiftliang/NewGame
        public static void loginTest(string host, int port)
        {
            pc = new PomeloClient();

            pc.NetWorkStateChangedEvent += (state) =>
            {
                Console.WriteLine(state);
            };


            pc.initClient(host, port, () =>
            {
                pc.connect(new JsonObject(), data =>
                {
                    Console.WriteLine("on data back" + data.ToString());
                    JsonObject msg = new JsonObject();
                    msg["uid"]     = 111;
                    pc.request("gate.gateHandler.queryEntry", msg, OnQuery);
                });
            });
        }
コード例 #25
0
    void Start()
    {
        //listen on network state changed event
        pomeloClient.NetWorkStateChangedEvent += (state) =>
        {
            Debug.logger.Log("CurrentState is:" + state);
        };

        pomeloClient.initClient(host, port, () =>
        {
            //The user data is the handshake user params
            JsonObject user = new JsonObject();
            //user["uid"] = userName;
            pomeloClient.connect(user, data =>
            {
                //process handshake call back data
                JsonObject msg = new JsonObject();
                msg["uid"]     = userName;
                pomeloClient.request("connector.entryHandler.entry", msg, OnQuery);
            });
        });
    }
コード例 #26
0
    void OnQuery(JsonObject result)
    {
        if (Convert.ToInt32(result["code"]) == 200)
        {
            pomeloClient.disconnect();

            string host = (string)result["host"];
            int    port = Convert.ToInt32(result["port"]);

            pomeloClient = new PomeloClient();

            pomeloClient.initClient(host, port, () =>
            {
                //The user data is the handshake user params
                JsonObject user = new JsonObject();
                pomeloClient.connect(user, data =>
                {
                    Entry();
                });
            });
        }
    }
コード例 #27
0
    // Start is called before the first frame update
    void Start()
    {
        string       host    = "127.0.0.1";//(www.xxx.com/127.0.0.1/::1/localhost etc.)
        int          port    = 3010;
        PomeloClient pclient = new PomeloClient();

        //listen on network state changed event
        pclient.NetWorkStateChangedEvent += (state) =>
        {
            Debug.Log("state changed " + state);
        };

        pclient.initClient(host, port, () =>
        {
            //The user data is the handshake user params
            JObject user = JObject.Parse("{}");
            pclient.connect(user, data =>
            {
                Debug.Log("发送消息");
                var msg = JObject.Parse(@"{
                    'name': 'bruce',
                    'custom': { 'field1': 7, 'field2': 0.9, 'field3': 9.0, 'field4': false, 'arr': [0,1,0,1] },
                    'customArr': [
                        { 'field1': 123, 'field2': 1.1, 'field3': 2.1, 'arr': [1,2,3], 'field4': true },
                        { 'field1': 321, 'field2': 1.2, 'field3': 2.2, 'arr': [4,5,6], 'field4': false },
                        { 'field1': 234, 'field2': 1.3, 'field3': 2.3, 'arr': [7,8,9], 'field4': true },
                    ],
                    'i32arr': [987, 654, 321],
                    'flarr': [9.87, 6.54, 3.21]
                }");
                pclient.request("connector.entryHandler.entry", msg, (resp) =>
                {
                    //process the data
                    Debug.Log("收到服务端返回" + resp.ToString());
                });
            });
        });
    }
コード例 #28
0
ファイル: Network.cs プロジェクト: yuchenwuhen/skillEditor
 public void Connect(string host, int port, Action <NetWorkState> action = null)
 {
     this.host   = host;
     this.port   = port;
     this.action = action;
     // BDebug.Log("连接:" + host);
     client.initClient(host, port, () =>
     {
         client.connect((data) =>
         {
             netWorkState = NetWorkState.WORK;
             IEnumeratorTool.ExecAction(() =>
             {
                 //UIWidgetMgr.Inst.Turn_Chrysanthemum.Hide();
                 if (action != null)
                 {
                     action(netWorkState);
                     action = null;
                 }
             });
         });
     });
 }
コード例 #29
0
ファイル: NetWorkMgr.cs プロジェクト: swiftliang/NewGame
 public void LoginGameServer(Action <GameInfo> cb)
 {
     _GameSvrConnection.disconnect();
     _GameSvrConnection.initClient(_gameSvrIP, _gameSvrPort, () =>
     {
         _GameSvrConnection.connect(null, data =>
         {
             Debug.Log("connect connector data: " + data.ToString());
             JsonObject msg = new JsonObject();
             msg["uid"]     = _loginInfo.uid;
             msg["token"]   = _loginInfo.token;
             msg["game"]    = "MDGame";
             _GameSvrConnection.request(RequestMsg.REQUEST_ENTER, msg, result =>
             {
                 if (cb != null)
                 {
                     Message retMsg = (Message)result;
                     GameInfo ginfo = JsonReader.Deserialize <GameInfo>(retMsg.rawString);
                     cb(ginfo);
                 }
             });
         });
     });
 }
コード例 #30
0
    //Login the chat application and new PomeloClient.
    void Login()
    {
        userName = infield_username.text; // 获取输入框中的信息
        channel  = infield_channelid.text;

        if (userName == "" || channel == "")
        {
            return;
        }

        string host = "127.0.0.1"; // game-server的host和port
        int    port = 3014;

        pomeloClient = new PomeloClient();

        //listen on network state changed event
        pomeloClient.NetWorkStateChangedEvent += (state) =>
        {
            Debug.logger.Log("CurrentState is:" + state);
        };

        // 连接gate 得到connect的host和port
        pomeloClient.initClient(host, port, () =>
        {
            //The user data is the handshake user params
            JsonObject user = new JsonObject();
            //user["uid"] = userName;
            pomeloClient.connect(user, data =>
            {
                //process handshake call back data
                JsonObject msg = new JsonObject();
                msg["uid"]     = userName;
                pomeloClient.request("gate.gateHandler.queryEntry", msg, OnQuery);
            });
        });
    }
コード例 #31
0
        //工作
        private void DoWork()
        {
            while (_isWorking)
            {
                //
                if (_workState == WorkState.ConnectGateState)
                {
                    JW.Common.Log.LogD("Pomelo 开始连接网关");
                    //释放
                    if (_pomeloClient != null)
                    {
                        _pomeloClient.NetWorkStateChangedEvent -= OnPemeloNetworkStateChange;
                        _pomeloClient.disconnect();
                        _pomeloClient.Dispose();
                        _pomeloClient = null;
                    }
                    _pomeloClient = new PomeloClient();
                    _pomeloClient.NetWorkStateChangedEvent += OnPemeloNetworkStateChange;
                    //
                    _pomeloClient.initClient(GateIp, GatePort, delegate()
                    {
                        //
                        _pomeloClient.on(OnPomeloReceiveNetMsg);
                        //套接字建立成功
                        _pomeloClient.connect(null, delegate(JsonObject data)
                        {
                            //握手回来
                            //开始查询游戏服务器地址
                            JW.Common.Log.LogD("Pomelo网关握手回来");
                            _workState = WorkState.ConnectGateQueryGSvrState;
                        });
                    });
                    //
                    _workState = WorkState.ConnectGateWaitingState;
                    Thread.Sleep(200);
                    continue;
                }

                if (_workState == WorkState.ConnectGateWaitingState)
                {
                    //
                    Thread.Sleep(200);
                }
                //请求查询游戏服务器地址
                if (_workState == WorkState.ConnectGateQueryGSvrState)
                {
                    JW.Common.Log.LogD("Pomelo 请求查询游戏服务器地址和端口");
                    string     route      = MSG_Query_Connector;
                    JsonObject jsonObject = new JsonObject();
                    SendJsonMsg(route, jsonObject);
                    //
                    _workState = WorkState.ConnectGateQueryGSvrWaitingState;
                    Thread.Sleep(200);
                    continue;
                }
                //
                if (_workState == WorkState.ConnectGateQueryGSvrWaitingState)
                {
                    //
                    Thread.Sleep(200);
                }

                //连接游戏服务器
                if (_workState == WorkState.ConnectGameSvrState)
                {
                    //释放网关用过的
                    if (_pomeloClient != null)
                    {
                        //去掉下
                        _pomeloClient.NetWorkStateChangedEvent -= OnPemeloNetworkStateChange;
                        _pomeloClient.disconnect();
                        _pomeloClient.Dispose();
                        _pomeloClient = null;
                    }
                    //
                    _pomeloClient = new PomeloClient();
                    _pomeloClient.NetWorkStateChangedEvent += OnPemeloNetworkStateChange;
                    //
                    JW.Common.Log.LogD("Pomelo 连接游戏服务器:{0}:{1}", _gameSvrIp, _gameSvrPort);
                    _pomeloClient.initClient(_gameSvrIp, _gameSvrPort, delegate()
                    {
                        //套接字建立成功
                        _pomeloClient.on(OnPomeloReceiveNetMsg);
                        //
                        _pomeloClient.connect(null, delegate(JsonObject data)
                        {
                            //握手回来
                            JW.Common.Log.LogD("------------>Pomelo Good Net<-----------------");
                            _workState = WorkState.ConnectGameSvrSuccessed;
                            if (CurSessionState == SessionState.SessionRetry)
                            {
                                JW.Common.Log.LogD("Pomelo Retry Connect Successed");
                            }
                            //成功
                            CurSessionState = SessionState.SessionSuccessed;
                        });
                        //
                    });
                    _workState = WorkState.ConnectGameSvrWaitingState;
                    Thread.Sleep(200);
                    continue;
                }

                if (_workState == WorkState.ConnectGameSvrWaitingState)
                {
                    //
                    Thread.Sleep(200);
                }

                if (_workState == WorkState.ConnectGameSvrRetryState)
                {
                    //
                    Thread.Sleep(200);
                }
                //
                if (_workState == WorkState.ConnectGameSvrSuccessed)
                {
                    Thread.Sleep(1000);
                }
            }
        }