/// <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); } }
int tryCount; //尝试连接次数 #endregion 私有成员变量 #region 公共方法 /// <summary> /// 更新,在NetworkMgr的Update中被调用 /// </summary> 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(); } }