/// <summary> /// 发送数据包 /// </summary> public void SendPacket(short id, IUdpPacket packet) { senderBuffer.SetWriterIndex(0); senderBuffer.WriteInt16(id); packet.Write(senderBuffer); byte[] packetBytes = senderBuffer.ToArray(); SendBytes(packetBytes, 0, packetBytes.Length); }
/// <summary> /// 解析数据包 /// </summary> private void Parser(short packId, ByteBuffer reader) { IUdpPacket packet = CheckUdpPacketType(packId); if (packet != null) { packet.Read(reader); //TODO 缓冲 PacketTuple <IUdpPacket> tuple = new PacketTuple <IUdpPacket>(); tuple.SetPacket(packId, packet); readPackets.Enqueue(tuple); } }
/// <summary> /// 看一下UDP的包 /// </summary> public IUdpPacket TryPeekPacket() { if (UdpChnl.State != EConnetState.EConneted) { return(null); } PacketTuple <IUdpPacket> packet = UdpChnl.TryPeekPacket(); if (packet != null) { IUdpPacket data = packet.packetObj; // ObjectCache.Cache(item); TODO 做一个缓存 return(data); } return(null); }