Пример #1
0
        /// <summary>
        /// 发送消息,把消息加入发送队列
        /// </summary>
        /// <param name='obj'>消息对象</param>
        /// <param name='type'>消息类型</param>
        /// <param name='encrypt'>是否加密</param>
        public void SendClientMsg(object obj, ushort type, bool encrypt)
        {
            MsgData msgData;

            try
            {
                msgData          = new MsgData();
                msgData.cType    = type;
                msgData.bEncrypt = encrypt;
                //msgData.obj = obj;
                byte[] item = ToByteArray(obj, type);

                msgData.obj = (object)item;
                sendMsgQueue.Add(msgData);
            }
            catch
            {
                DEBUG.Networking(DEBUG.TRACER_LOG + "Send message except.", LogType.Exception);
            }
        }
Пример #2
0
        public int tryCount;                                //尝试连接次数

        #endregion 私有成员变量

        #region 公共成员方法

        public void Update()
        {
            if (Connected)
            {
                //发送消息
                if (sendMsgQueue.Count > 0)
                {
                    MsgData msgData = sendMsgQueue[0];
                    NetClient.SendCliMsg(msgData.obj, msgData.cType, msgData.bEncrypt);
                    sendMsgQueue.RemoveAt(0);
                }

                if (DisconnectFlag)
                {
                    Disconnect();
                }
            }

            if (!DisconnectFlag)
            {
                NetClient.Update();
            }
        }