private void DoReceiveInThread() { EndPoint remotePoint = IPUtils.GetIPEndPointAny(AddressFamily.InterNetwork, 0); int cnt = m_SystemSocket.ReceiveFrom(m_RecvBufferTemp, m_RecvBufferTemp.Length, SocketFlags.None, ref remotePoint); if (cnt > 0) { m_RecvBufferTempReader.Attach(m_RecvBufferTemp, cnt); byte[] m_32b = new byte[4]; m_RecvBufferTempReader.ReadBytes(m_32b, 0, 4); uint sid = BitConverter.ToUInt32(m_32b, 0); //uint sid = m_RecvBufferTempReader.ReadUInt(); lock (m_mapSession) { ISession session = null; if (sid == 0) { //来自Client的第1个包,只能是鉴权包 sid = SessionID.NewID(); session = new KCPSession(sid, HandleSessionSend, m_listener); m_mapSession.Add(session.id, session); } else { session = m_mapSession[sid]; } if (session != null) { session.Active(remotePoint as IPEndPoint); session.DoReceiveInGateway(m_RecvBufferTemp, cnt); } else { Debuger.LogWarning("无效的包! sid:{0}", sid); } } } }