void AddResultPackage(PomeloPackage pkg)
 {
     lock (m_pomeloBackPackage)
     {
         m_pomeloBackPackage.Enqueue(pkg);
     }
 }
    public void Request(string route, LuaInterface.LuaTable paramsTable, LuaInterface.LuaFunction func)
    {
        if (pc != null)
        {
            JsonObject msg = new JsonObject();
            IEnumerator <DictionaryEntry> paramList = paramsTable.ToDictTable().GetEnumerator();
            while (paramList.MoveNext())
            {
                DictionaryEntry curr = paramList.Current;
                Debug.Log("key " + curr.Key + " value: " + curr.Value);
                msg[curr.Key.ToString()] = curr.Value;
            }

            pc.request(route, msg, (result) =>
            {
                PomeloPackage pkg = new PomeloPackage();
                if (func == null)
                {
                    Debug.LogError("callback function is null!");
                }

                pkg.luaFunc    = func;
                pkg.ReturnData = result.ToString();
                AddResultPackage(pkg);
            });
        }
        else
        {
            Debug.LogError("Pomelo Client is null");
        }
    }
    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);
                            }
                        });
                    });
                }
            });
        });
    }
    void ProcessRespond()
    {
        lock (m_pomeloBackPackage)
        {
            while (m_pomeloBackPackage.Count > 0)
            {
                PomeloPackage pkg = m_pomeloBackPackage.Dequeue();
                if (pkg.luaFunc == null)
                {
                    Debug.Log("fuck1");
                }


                pkg.luaFunc.Call(pkg.ReturnData);
            }
        }
    }