public static NFCNetDispatcher Instance() { if (_instance == null) { _instance = new NFCNetDispatcher(); } return(_instance); }
void dispatchMsgs() { while (true) { int nReadSize = m_recvPool.ReadSize; int nReadPos = m_recvPool.ReadPos; // 消息没有包头大就推出循环 if (nReadSize < ConstDefine.NF_PACKET_HEAD_SIZE) { break; } int offset = 0; // 跳过包头标签定义 UInt32 length = BitConverter.ToUInt32(m_recvPool.Buffer, nReadPos + offset); offset += sizeof(UInt32); UInt16 nMsgID = BitConverter.ToUInt16(m_recvPool.Buffer, nReadPos + offset); offset += sizeof(UInt16); // 消息包还没有完全收完立即退出 length = ConvertUint32(length); nMsgID = ConvertUint16(nMsgID); Debug.LogFormat("RecvData {0} \t {1}", length, nMsgID); if (nReadSize < length + ConstDefine.NF_PACKET_LEN_MSG_LEN) { break; } m_recvPool.ReadPos += (int)length + (int)ConstDefine.NF_PACKET_LEN_MSG_LEN; Debug.LogFormat("Recv:{0}", nMsgID); nReadPos += (int)ConstDefine.NF_PACKET_HEAD_SIZE; length -= ConstDefine.NF_PACKET_LEN_MSG_ID; MemoryStream mem = new MemoryStream(m_recvPool.Buffer, nReadPos, (int)length); NFCNetDispatcher.Instance().dispatchMessage(nMsgID, mem); if (m_curState != State.CONNECTED) { break; } } }
public void AddReceiveCallBack(NFMsg.EGameMsgID id, NFCMessageDispatcher.MessageHandler netHandler) { NFCNetDispatcher.Instance().AddReceiveCallBack((UInt16)id, netHandler); }