public static Int32 PopMsgFromMemQueue(CMemQueue cMsgQueue, CMsg cMsg) { Int32 n32Get = cMsgQueue.GetFront(cMsg.GetMsgBuffer(), (UInt32)s_n32MsgHeaderSize); if (0 != n32Get) { return(n32Get); } Int32 n32MsgSize = cMsg.GetMsgSize(); // if (n32MsgSize >= cMsg.m_n32MsgSize) // { // return -2; // } Int32 n32Pop = cMsgQueue.PopFront(cMsg.GetMsgBuffer(), (UInt32)n32MsgSize); if (0 != n32Pop) { return(-3); } cMsg.SetReadPos(s_n32MsgHeaderSize); cMsg.SetWritePos(n32MsgSize); return(0); }
public void SendMsg(ProtoBuf.IExtensible pMsg, Int32 n32MsgID) { if (m_Client != null) { //清除stream mSendStream.SetLength(0); mSendStream.Position = 0; //序列到stream ProtoBuf.Serializer.Serialize(mSendStream, pMsg); CMsg pcMsg = new CMsg((int)mSendStream.Length); pcMsg.SetProtocalID(n32MsgID); pcMsg.Add(mSendStream.ToArray(), 0, (int)mSendStream.Length); //ms.Close(); #if UNITY_EDITOR #else try { #endif #if LOG_FILE && UNITY_EDITOR if (n32MsgID != 8192 && n32MsgID != 16385) { string msgName = ""; if (Enum.IsDefined(typeof(GCToBS.MsgNum), n32MsgID)) { msgName = ((GCToBS.MsgNum)n32MsgID).ToString(); } else if (Enum.IsDefined(typeof(GCToCS.MsgNum), n32MsgID)) { msgName = ((GCToCS.MsgNum)n32MsgID).ToString(); } else if (Enum.IsDefined(typeof(GCToLS.MsgID), n32MsgID)) { msgName = ((GCToLS.MsgID)n32MsgID).ToString(); } else if (Enum.IsDefined(typeof(GCToSS.MsgNum), n32MsgID)) { msgName = ((GCToSS.MsgNum)n32MsgID).ToString(); } using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"E:\Log.txt", true)) { sw.WriteLine(Time.time + " 发送消息:\t" + n32MsgID + "\t" + msgName); } } #endif m_Client.GetStream().Write(pcMsg.GetMsgBuffer(), 0, (int)pcMsg.GetMsgSize()); #if UNITY_EDITOR #else } catch (Exception exc) { Debugger.LogError(exc.ToString()); Close(); } #endif } }
public void SendMsg(IMessage pMsg, Int32 n32MsgID) { if (m_Client != null) { Debug.Log("send msg " + n32MsgID); ByteString bs = pMsg.ToByteString(); CMsg pcMsg = new CMsg((int)bs.Length); pcMsg.SetProtocalID(n32MsgID); pcMsg.Add(bs.ToByteArray(), 0, (int)bs.Length); #if UNITY_EDITOR #else try { #endif #if LOG_FILE && UNITY_EDITOR if (n32MsgID != 8192 && n32MsgID != 16385) { string msgName = ""; if (Enum.IsDefined(typeof(GCToBS.MsgNum), n32MsgID)) { msgName = ((GCToBS.MsgNum)n32MsgID).ToString(); } else if (Enum.IsDefined(typeof(GCToCS.MsgNum), n32MsgID)) { msgName = ((GCToCS.MsgNum)n32MsgID).ToString(); } else if (Enum.IsDefined(typeof(GCToLS.MsgID), n32MsgID)) { msgName = ((GCToLS.MsgID)n32MsgID).ToString(); } else if (Enum.IsDefined(typeof(GCToSS.MsgNum), n32MsgID)) { msgName = ((GCToSS.MsgNum)n32MsgID).ToString(); } using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"E:\Log.txt", true)) { sw.WriteLine(Time.time + " 发送消息:\t" + n32MsgID + "\t" + msgName); } } #endif m_Client.GetStream().Write(pcMsg.GetMsgBuffer(), 0, (int)pcMsg.GetMsgSize()); #if UNITY_EDITOR #else } catch (Exception exc) { Debug.LogError(exc.ToString()); Close(); } #endif } }
/// <summary> /// 发送消息 /// </summary> /// <param name="pMsg"></param> /// <param name="MsgID"></param> public void SendMessage(LuaByteBuffer data, Int32 MsgID) { if (client != null) { //清除stream (可见,我们要发送消息,一定要有发送消息发送流) send_streams.SetLength(0); send_streams.Position = 0; //添加到send_streams里面 send_streams.Write(data.buffer, 0, data.buffer.Length); CMsg sendMessage = new CMsg((int)send_streams.Length); //添加消息头部 sendMessage.SetProtocalID(MsgID); sendMessage.Add(send_streams.ToArray(), 0, (int)send_streams.Length); //发送消息的最重要的代码,将网络数据流发送到指定服务器流中 client.GetStream().Write(sendMessage.GetMsgBuffer(), 0, (int)sendMessage.GetMsgSize()); } }
public void SendMsg(LuaByteBuffer pMsg, Int32 n32MsgID) { Debug.Log("发送消息:<color=#9400D3>" + n32MsgID + "</color>"); if (m_Client != null) { CMsg pcMsg = new CMsg(pMsg.Length); pcMsg.SetProtocalID(n32MsgID); pcMsg.Add(pMsg.buffer, 0, pMsg.Length); try { m_Client.GetStream().Write(pcMsg.GetMsgBuffer(), 0, (int)pcMsg.GetMsgSize()); } catch (Exception exc) { Debugger.LogError(exc.ToString()); Close(); } } }