public ServerChannel(KcpCon con) { m_Dispose = false; m_Conv = con.Conv; m_ConId = con.ConId; m_Con = con; m_Heartbeat = new ServerHeartbeatProcessing(); m_RecvPackets = new HConcurrentQueue <Packet>(); m_SendPackets = new HConcurrentQueue <Packet>(); }
public bool RecvReliablePackets(ServerChannel channel, List <Packet> packets, IChannelListener listener, ServerHeartbeatProcessing heartbeat) { while (true) { int size = channel.Recv(m_RecvBuffer, 0, m_RecvBuffer.Length); if (size <= 0) { break; } if (size == 8) { ByteReadMemory memory = new ByteReadMemory(m_RecvBuffer, 0, size); uint flag = memory.ReadUInt(); uint conv = memory.ReadUInt(); if (conv == channel.Conv) { if (flag == KcpConstants.Flag_Connect) { channel.SetConnectedStatus(true); if (listener != null) { listener.OnAddChannel(channel); } continue; } if (flag == KcpConstants.Flag_Disconnect) { channel.SetConnectedStatus(false); if (listener != null) { listener.OnRemoveChannel(channel); } continue; } if (flag == KcpConstants.Flag_Heartbeat) { heartbeat.UpdateHeartbeat(channel, m_RecvBuffer, 0, size); continue; } } } PacketProcessing.Recv(m_RecvBuffer, 0, size, packets); } return(packets.Count > 0); }