/// <summary> /// 处理数据包,并发送消息通知 /// </summary> public void HandleNext() { PackageIn pack = null; lock (m_packages) { pack = m_packages.Dequeue(); } NetworkManager.instance.Read(pack); }
/// <summary> /// 添加入包 /// </summary> /// <param name="package"></param> public void AddPackage(PackageIn package) { if (package == null) { UnityEngine.Debug.LogError("AddPackage pack is null "); } lock (m_packages) { m_packages.Enqueue(package); } }
private bool ProcessPacket() { try { byte[] body = new byte[m_Receive.ReadLength]; Array.Copy(m_Receive.Stream.GetBuffer(), 0, body, 0, m_Receive.ReadLength); PackageIn package = new PackageIn(body, 0, m_Receive.ReadLength); m_netReader.AddPackage(package); m_Receive.PrepareReadHeader(HEAD_LENGTH); if (NetworkManager.instance.IsDebug) { NetworkManager.instance.Error("pkg recevie now " + package.code + " process " + Thread.CurrentThread.ManagedThreadId.ToString()); } } catch (Exception e) { NetworkManager.instance.Error("Socket ProcessPacket: " + e.Message); return(false); } return(true); }