private static bool _SampleMsgCreater(UInt16 id, ref CSLib.Framework.CMessage msg) { Message.EMsgID msgID = (Message.EMsgID)id; switch (msgID) { case Message.EMsgID.EMID_SAMPLE_NTF_OK: { msg = new Message.CMsgSampleNtfOk(); return(true); } case Message.EMsgID.EMID_SAMPLE_REQ_SAY: { msg = new Message.CMsgSampleReqSay(); return(true); } case Message.EMsgID.EMID_SAMPLE_RES_SAY: { msg = new Message.CMsgSampleResSay(); return(true); } } return(false); }
// private void _OnMsgTestReqSay(CSLib.Framework.CMessageLabel msgLabel, CSLib.Framework.CMessage msg) { Message.CMsgSampleReqSay reqSay = (Message.CMsgSampleReqSay)msg; Console.WriteLine("收到:" + reqSay.m_string + "{" + m_netStub.LocalIPEndPoint.ToString() + "<---" + m_netStub.PeerIPEndPoint.ToString() + "}"); Message.CMsgSampleResSay resSay = new Message.CMsgSampleResSay(); resSay.m_string = "Sever No.["; resSay.m_string += m_number.ToString(); resSay.m_string += "]"; resSay.m_bool = reqSay.m_bool; resSay.m_byte = reqSay.m_byte; resSay.m_bytes = reqSay.m_bytes; resSay.m_double = reqSay.m_double; resSay.m_float = reqSay.m_float; resSay.m_int = reqSay.m_int; resSay.m_long = reqSay.m_long; resSay.m_short = reqSay.m_short; resSay.m_uint = reqSay.m_uint; resSay.m_ulong = reqSay.m_ulong; resSay.m_ushort = reqSay.m_ushort; m_number++; CSLib.Utility.CStream streamRes = new CSLib.Utility.CStream(); resSay.Serialize(streamRes); m_netStub.SendAsync(streamRes); }
public static bool MsgCreater(UInt16 type, UInt16 id, ref CSLib.Framework.CMessage msg) { Message.EMsgType msgType = (Message.EMsgType)type; switch (msgType) { case Message.EMsgType.EMT_SAMPLE: { return(_SampleMsgCreater(id, ref msg)); } } return(false); }
public bool SendMessage(CSLib.Framework.CNetMessage msgRequest, CSLib.Framework.CMessage msgResponse, Int32 delaySecond = 3) { if (CReconnectMgr.Instance.SimulateSocketClose) { UDLib.Utility.CDebugOut.Log("客户端模拟断网"); m_tcpClient.Close(); m_tcpClient.CbTerminate(); return(false); } if (msgRequest == null) { UDLib.Utility.CDebugOut.LogError("SendMessage : msgRquest == null"); return(false); } if (msgResponse == null) { UDLib.Utility.CDebugOut.LogError("SendMessage : msgResponse == null"); return(false); } if (m_tcpClient == null) { UDLib.Utility.CDebugOut.LogError("SendMessage : m_tcpClient == null"); return(false); } if (!m_tcpClient.IsValid()) { return(false); } Int64 curTicks = DateTime.Now.Ticks / 10000; // 转成毫秒 if (m_tcpClient.DelayedMsg.ContainsKey(msgResponse.UniqueID)) { if (curTicks < m_tcpClient.DelayedMsg.GetObject(msgResponse.UniqueID)) { return(false); } else { m_tcpClient.DelayedMsg.DelObject(msgResponse.UniqueID); } } //UnityEngine.Profiling.Profiler.BeginSample("CMoniBehaviour > SendMessage"); { byte tmpServer = CSLib.Utility.CBitHelper.GetHighUInt8(msgRequest.MsgType); byte tmpFunc = CSLib.Utility.CBitHelper.GetLowUInt8(msgRequest.MsgType); if (!CSLib.Framework.CMsgFactory.Instance.IsIgnoreTrace(tmpServer, tmpFunc, msgRequest.Id)) { //发送消息前加入本地缓存,在这里做可以过滤掉心跳 UDLib.Utility.CDebugOut.Log("SendMessage : uServer = " + tmpServer.ToString() + "; uFunc = " + tmpFunc.ToString() + "; uID = " + msgRequest.Id.ToString() + ", reqIndex" + msgRequest.GetReqIndex()); // 超时重发机制, 非ack消息,缓存序列号,待收到ack返回从缓存移除 m_tcpClient.CacheMessage(msgRequest); m_tcpClient.DelayedMsg.AddObject(msgResponse.UniqueID, curTicks + delaySecond * 1000); // 第二个参数转成毫秒 #if DEBUG m_sendStatisticsNum.AddNum(tmpServer.ToString() + " -> " + tmpFunc.ToString()); #endif } } //UnityEngine.Profiling.Profiler.EndSample(); return(_SendMessage(msgRequest)); }
private void _OnMsgTestResSay(CSLib.Framework.CMessageLabel msgLabel, CSLib.Framework.CMessage msg) { Message.CMsgSampleResSay resSay = (Message.CMsgSampleResSay)msg; Console.WriteLine("收到:" + resSay.m_string + resSay.m_bool + " " + resSay.m_byte + " " + resSay.m_bytes[0] + " " + resSay.m_bytes[1] + " " + resSay.m_bytes[2] + " " + resSay.m_bytes[3] + " " + resSay.m_bytes[4] + " " + resSay.m_double + " " + resSay.m_float + " " + resSay.m_int + " " + resSay.m_long + " " + resSay.m_short + " " + resSay.m_uint + " " + resSay.m_ulong + " " + resSay.m_ushort); }
private void _OnMsgTestNtfOk(CSLib.Framework.CMessageLabel msgLabel, CSLib.Framework.CMessage msg) { ; }