UdpPacket.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace ToolsClassLibrary.UDP
  8. {
  9. [Serializable]
  10. public class UdpPacket
  11. {
  12. public long sequence { get; set; }//所属组的唯一序列号 包编号
  13. public int total { get; set; }//分包总数
  14. public int index { get; set; }//消息包的索引
  15. public byte[] data { get; set; }//包的内容数组
  16. public int dataLength { get; set; }//分割的数组包大小
  17. public int remainder { get; set; }//最后剩余的数组的数据长度
  18. public int sendtimes { get; set; }//发送次数
  19. public IPEndPoint remoteip { get; set; }//接受该包的远程地址
  20. public bool IsRequireReceiveCheck { get; set; }//获得或设置包收到时是否需要返回确认包
  21. public static int HeaderSize = 30000;
  22. public UdpPacket(long sequence, int total, int index, byte[] data, int dataLength, int remainder, string desip, int port)
  23. {
  24. this.sequence = sequence;
  25. this.total = total;
  26. this.index = index;
  27. this.data = data;
  28. this.dataLength = dataLength;
  29. this.remainder = remainder;
  30. this.IsRequireReceiveCheck = true;//默认都需要确认包
  31. //构造远程地址
  32. IPAddress ipA = IPAddress.Parse(desip);
  33. this.remoteip = new IPEndPoint(ipA, port);
  34. }
  35. //把这个对象生成byte[]
  36. public byte[] ToArray()
  37. {
  38. return SerializationUnit.SerializeObject(this);
  39. }
  40. }
  41. }