Ejemplo n.º 1
0
 /// <summary>
 /// Invoke the callback when the server return messge .
 /// </summary>
 /// <param name='pomeloMessage'>
 /// Pomelo message.
 /// </param>
 public void InvokeCallBack(uint id, JsonNode_Object data)
 {
     if (!callBackMap.ContainsKey(id))
     {
         return;
     }
     IEnumeratorTool.ExecAction(() =>
     {
         callBackMap[id](data);
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// If the event exists,invoke the event when server return messge.
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        ///
        public void InvokeOnEvent(string route, JsonNode_Object msg)
        {
            if (!this.eventMap.ContainsKey(route))
            {
                return;
            }

            List <Action <JsonNode_Object> > list = eventMap[route];

            foreach (Action <JsonNode_Object> action in list)
            {
                IEnumeratorTool.ExecAction(() =>
                {
                    action.Invoke(msg);
                });
            }
        }
Ejemplo n.º 3
0
 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;
                 }
             });
         });
     });
 }
Ejemplo n.º 4
0
    private void NetWorkStateChange(NetWorkState state)
    {
        netWorkState = state;
        BDebug.Log(state);
        switch (state)
        {
        case NetWorkState.CLOSED:
        {
            BDebug.Log("关闭:" + host);
        }
        break;

        case NetWorkState.CONNECTING:
        {
            BDebug.Log("连接:" + host + " --连接中");
        }
        break;

        case NetWorkState.CONNECTED:
        {
            BDebug.Log("连接:" + host + " --连接上");
        }
        break;

        case NetWorkState.WORK:
        {
            IEnumeratorTool.ExecAction(() =>
                {
                    //UIWidgetMgr.Inst.Turn_Chrysanthemum.Hide();
                });
            BDebug.Log("连接:" + host + " --正常工作");
        }
        break;

        case NetWorkState.DISCONNECTED:
        {
            if (isByClientCall)
            {
                isByClientCall = false;
            }
            else
            {
                if (OnDisconnect != null)
                {
                    IEnumeratorTool.ExecAction(() =>
                        {
                            OnDisconnect();
                        });
                }
            }
        }
        break;

        case NetWorkState.TIMEOUT:
        case NetWorkState.ERROR:
        {
            if (OnTimeOut != null)
            {
                IEnumeratorTool.ExecAction(() =>
                    {
                        OnTimeOut();
                    });
            }
        }
        break;

        default:
            break;
        }
    }