public void Send(EndPoint destination, UDPPacketType type = UDPPacketType.DAT, UDPPacketFlags flags = UDPPacketFlags.NUL, byte[] data = null, int[] intData = null) { InitSequence(destination); UDPConnectionData sq = _sequences[destination.ToString()]; if ((data != null && data.Length < _maxMTU) || data == null) { SendPacket(new UDPPacket() { Dst = destination, Id = sq.PacketId, Type = type, Flags = flags, Data = data }); sq.PacketId++; } else if (data != null && data.Length >= _maxMTU) { int i = 0; List <UDPPacket> PacketsToSend = new List <UDPPacket>(); while (i < data.Length) { int min = i; int max = _maxMTU; if ((min + max) > data.Length) { max = data.Length - min; } byte[] buf = data.Skip(i).Take(max).ToArray(); PacketsToSend.Add(new UDPPacket() { Dst = destination, Id = sq.PacketId, Type = type, Flags = flags, Data = buf }); i += _maxMTU; } foreach (UDPPacket p in PacketsToSend) { p.Qty = PacketsToSend.Count; SendPacket(p); } sq.PacketId++; } else { throw new Exception("This should not happen"); } if (sq.PacketId > PacketIdLimit) { sq.PacketId = 0; } }
public UDPPacket(byte[] data, UDPPacketType type = UDPPacketType.Message) { Type = type; Data = data; }
public UDPPacket(UDPPacketType type = UDPPacketType.Message) { Type = type; }