构造UDP数据包的字节数组

Posted

技术标签:

【中文标题】构造UDP数据包的字节数组【英文标题】:Byte Array to Struct UDP Packet 【发布时间】:2020-06-06 16:51:46 【问题描述】:

我目前正忙于我的项目。我目前从游戏中接收 UDP 数据包。这些数据包包含字节数组。这些字节数组需要转换为结构体。

我已经解决了这个问题的前一个问题: F1 2019 UDP decoding

我已经完成了其中的一部分工作。我使用此代码将字节数组转换为结构:

PacketHeader ByteArrayToPacketHeader(byte[] bytes)
            
                GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                PacketHeader stuff;
                try
                
                    stuff = (PacketHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PacketHeader));
                
                finally
                
                    handle.Free();
                
                return stuff;
            

我的数据包头(结构)看起来像这样:

public struct PacketHeader
    
        public ushort m_packetFormat;         // 2019
        public byte m_gameMajorVersion;     // Game major version - "X.00"
        public byte m_gameMinorVersion;     // Game minor version - "1.XX"
        public byte m_packetVersion;        // Version of this packet type, all start from 1
        public byte m_packetId;             // Identifier for the packet type, see below
        public ulong m_sessionUID;           // Unique identifier for the session
        public float m_sessionTime;          // Session timestamp
        public uint m_frameIdentifier;      // Identifier for the frame the data was retrieved on
        public byte m_playerCarIndex;       // Index of player's car in the array
    ;

通过这段代码,我得到了正确的信息。所以这行得通!

游戏通过同一个字节数组发送多个“包”(Structs)。

但是当我使用相同的代码将字节数组转换为新的结构布局时,我没有从数组中得到正确的信息。 示例:

PacketCarTelemetryData ByteArrayToPacketCarTelemetryData(byte[] bytes)
                
                    GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                    PacketCarTelemetryData stuff;
                    try
                    
                        stuff = (PacketCarTelemetryData)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PacketCarTelemetryData));
                    
                    finally
                    
                        handle.Free();
                    
                    return stuff;

此代码使用此结构布局:

public struct PacketCarTelemetryData
    
         public PacketHeader m_header;        // Header

         public CarTelemetryData m_carTelemetryData;

         public uint m_buttonStatus;        // Bit flags specifying which buttons are being pressed
                                      // currently - see appendices
    ;

在上面的结构中还存储了其他结构:

public struct CarTelemetryData
    

        public ushort m_speed;                    // Speed of car in kilometres per hour
        public float m_throttle;                 // Amount of throttle applied (0.0 to 1.0)
        public float m_steer;                    // Steering (-1.0 (full lock left) to 1.0 (full lock right))
        public float m_brake;                    // Amount of brake applied (0.0 to 1.0)
        public byte m_clutch;                   // Amount of clutch applied (0 to 100)
        public sbyte m_gear;                     // Gear selected (1-8, N=0, R=-1)
        public ushort m_engineRPM;                // Engine RPM
        public byte m_drs;                      // 0 = off, 1 = on
        public byte m_revLightsPercent;         // Rev lights indicator (percentage)
        public ushort m_brakesTemperature;     // Brakes temperature (celsius)
        public ushort m_tyresSurfaceTemperature; // Tyres surface temperature (celsius)
        public ushort m_tyresInnerTemperature; // Tyres inner temperature (celsius)
        public ushort m_engineTemperature;        // Engine temperature (celsius)
        public float tyresPressure;         // Tyres pressure (PSI)
        public byte m_surfaceType;           // Driving surface, see appendice
    ;

所以我现在的问题是,当我使用此代码将字节数组转换为此特定结构时,我没有得到我想要的信息。

附:车里没有36档,我的刹车也不是21760摄氏度……

有人有什么建议吗?

致以诚挚的问候,

编辑:

有关更多信息,这是我想读取数据包 CarTelemetryData 时得到的十六进制代码:

E3-07-01-15-01-06-F8-CE-BE-09-64-7F-EA-D1-DC-A1-16-41-91-01-00-00-13-7B-00-00-00-80-3F-36-53-7E-3C-00-00-00-00-00-02-F3-2F-00-64-1D-00-1D-00-1D-00-1D-00-74-00-74-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-74-00-00-00-80-3F-1B-F2-3A-3C-00-00-00-00-00-02-35-2D-00-22-1D-00-1D-00-1D-00-1D-00-69-00-69-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7B-00-00-00-80-3F-F3-59-A1-BA-00-00-00-00-00-02-59-2F-00-64-1D-00-1D-00-1D-00-1D-00-72-00-72-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-77-00-00-00-80-3F-FE-5F-3F-3C-00-00-00-00-00-02-3D-2E-00-3E-1D-00-1D-00-1D-00-1D-00-71-00-71-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-81-00-00-00-80-3F-89-78-23-3C-00-00-00-00-00-03-E0-28-00-00-1D-00-1D-00-1D-00-1D-00-77-00-78-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-77-00-00-00-80-3F-C3-73-98-3C-00-00-00-00-00-02-2F-2E-00-54-1D-00-1D-00-1D-00-1D-00-75-00-75-00-50-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-76-00-00-00-80-3F-F3-F4-BA-BA-00-00-00-00-00-02-21-2E-00-59-1D-00-1D-00-1D-00-1D-00-75-00-75-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7C-00-00-00-80-3F-4D-7D-04-3B-00-00-00-00-00-02-FB-2F-00-64-1D-00-1D-00-1D-00-1D-00-70-00-70-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-75-00-00-00-80-3F-84-45-AB-3C-00-00-00-00-00-02-BF-2D-00-31-1D-00-1D-00-1D-00-1D-00-77-00-77-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-80-00-00-00-80-3F-B5-8C-BD-3B-00-00-00-00-00-03-1B-28-00-00-1D-00-1D-00-1D-00-1D-00-71-00-71-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-72-00-00-00-80-3F-F8-D0-87-3A-00-00-00-00-00-02-63-2C-00-37-1D-00-1D-00-1D-00-1D-00-79-00-79-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7B-00-00-00-80-3F-FF-A7-60-3A-00-00-00-00-00-02-DE-2F-00-64-1D-00-1D-00-1D-00-1D-00-6E-00-6E-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7A-00-00-00-80-3F-B9-2E-2F-3C-00-00-00-00-00-02-D1-2F-00-64-1D-00-1D-00-1D-00-1D-00-75-00-75-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-74-00-00-00-80-3F-CD-1E-18-3A-00-00-00-00-00-02-3F-2D-00-23-1D-00-1D-00-1D-00-1D-00-6F-00-6F-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-73-00-00-00-80-3F-15-0F-AF-3B-00-00-00-00-00-02-A5-2B-00-0C-1D-00-1D-00-1D-00-1D-00-70-00-70-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7A-00-00-00-80-3F-2B-C0-14-3C-00-00-00-00-00-02-49-2F-00-64-1D-00-1D-00-1D-00-1D-00-6F-00-6F-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7F-00-00-00-80-3F-41-CA-C0-3C-00-00-00-00-00-03-85-2B-00-64-1D-00-1D-00-1D-00-1D-00-79-00-79-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-72-00-00-00-80-3F-07-1F-D5-3C-00-00-00-00-00-02-DE-2A-00-00-1D-00-1D-00-1D-00-1D-00-78-00-78-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-71-00-00-00-80-3F-DD-C0-1C-3C-00-00-00-00-00-02-DD-2A-00-00-1D-00-1D-00-1D-00-1D-00-6F-00-6F-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-31-00-97-96-96-3E-00-00-00-00-00-00-00-00-00-01-9B-17-00-00-1D-00-1D-00-1D-00-1D-00-62-00-62-00-4F-00-4F-00-59-00-59-00-58-00-58-00-5A-00-CD-CC-A8-41-CD-CC-A8-41-33-33-BB-41-33-33-BB-41-00-00-00-00-00-00-00-00

我知道根据这些信息,以下数字与游戏中发生的情况不符:

当前档位应该是: 1. 这是我知道的一个事实。

重飞百分比应低于 100%

温度应该低很多,

RPM 太高了(可能在 10000 左右是正常的)。

我希望这些信息就足够了。

【问题讨论】:

数据的字节序是什么?你是如何序列化这些数据的?是相反的相同代码吗?基本上,我担心填充; PacketHeader 的大小是 32,但您可能期望 23 还是什么?对吗? @MarcGravell 感谢您的快速回复!我所知道的是他们在 LittleEndian 中解码数组。我知道这意味着什么,但不知道如何处理它。我也不知道序列化是什么。我对此有点陌生...如果您不介意我想了解更多信息,因此如果您可以稍微解释一下或将我引导到可以了解它的某个网页,我会真的很感激。亲切的问候, 很多桌面 CPU 也是 little-endian,所以:它可以工作吗?你有一个我可以在这里查看的示例有效负载,十六进制和预期值。碰巧,这是我的专业领域。 @MarcGravell 我会尽快将十六进制发送给您,但我不明白预期值。我只是得到一大行十六进制代码,所有信息都存储在那里。至于你在下面的回答,我已经让 packetheader 工作了,但其余的都没有。 我很乐意帮助您尝试解决这个问题,但是:这是 1347 字节 - 这是什么意思?一个标头和一个遥测?大量的标题和遥测一个接一个?一个标题和很多遥测?它对于每个人来说都太大了...帮助我了解我在这里看到的内容 【参考方案1】:

假设这是与填充有关的布局问题,您可以使用显式字段布局将字段放置在您期望的位置。但是,如果还存在 endianness 问题,则会更加复杂。如果我们忽略字节顺序,也许:

    [StructLayout(LayoutKind.Explicit, Pack = 0, Size = 23)]
    public struct PacketHeader
    
        public static PacketHeader Read(ReadOnlySpan<byte> bytes)
            => MemoryMarshal.Cast<byte, PacketHeader>(bytes)[0];
        public void Write(Span<byte> bytes)
            => MemoryMarshal.Cast<byte, PacketHeader>(bytes)[0] = this;

        [FieldOffset(0)]
        public ushort m_packetFormat;         // 2019
        [FieldOffset(2)]
        public byte m_gameMajorVersion;     // Game major version - "X.00"
        [FieldOffset(3)]
        public byte m_gameMinorVersion;     // Game minor version - "1.XX"
        [FieldOffset(4)]
        public byte m_packetVersion;        // Version of this packet type, all start from 1
        [FieldOffset(5)]
        public byte m_packetId;             // Identifier for the packet type, see below
        [FieldOffset(6)]
        public ulong m_sessionUID;           // Unique identifier for the session
        [FieldOffset(14)]
        public float m_sessionTime;          // Session timestamp
        [FieldOffset(18)]
        public uint m_frameIdentifier;      // Identifier for the frame the data was retrieved on
        [FieldOffset(22)]
        public byte m_playerCarIndex;       // Index of player's car in the array
    ;

还要注意这里使用MemoryMarshal,这使得强制转换更容易。 byte[] 可以被视为一个跨度。

【讨论】:

【参考方案2】:

我们来了;这里有几件事要看;首先是规范中的[4] 等是指这些东西的固定数量,而不是其中一个 - 查看轮胎温度等;现在,您可以在 C# 中使用 fixed 缓冲区来执行此操作,但是使用起来真的很痛苦,因为它需要 unsafe 代码,所以我只使用了一些自定义四边形类型;我还明确列出了所有结构。我没有将标题读取两次,而是将其按顺序解析为 20 个汽车实例。

结果:占所有字节;演示代码。

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Explicit, Pack = 0, Size = 23)]
public struct PacketHeader

    [FieldOffset(0)]
    public ushort m_packetFormat;         // 2019
    [FieldOffset(2)]
    public byte m_gameMajorVersion;     // Game major version - "X.00"
    [FieldOffset(3)]
    public byte m_gameMinorVersion;     // Game minor version - "1.XX"
    [FieldOffset(4)]
    public byte m_packetVersion;        // Version of this packet type, all start from 1
    [FieldOffset(5)]
    public PacketType m_packetId;             // Identifier for the packet type, see below
    [FieldOffset(6)]
    public ulong m_sessionUID;           // Unique identifier for the session
    [FieldOffset(14)]
    public float m_sessionTime;          // Session timestamp
    [FieldOffset(18)]
    public uint m_frameIdentifier;      // Identifier for the frame the data was retrieved on
    [FieldOffset(22)]
    public byte m_playerCarIndex;       // Index of player's car in the array
;

public enum PacketType : byte

    Motion = 0, // Contains all motion data for player’s car – only sent while player is in control

    Session = 1,// Data about the session – track, time left

    LapData = 2,//  Data about all the lap times of cars in the session

    Event = 3, // Various notable events that happen during a session

    Participants = 4, // List of participants in the session, mostly relevant for multiplayer

    CarSetups = 5, // Packet detailing car setups for cars in the race

    CarTelemetry = 6,  // Telemetry data for all cars

    CarStatus = 7 //  Status data for all cars such as damage


[StructLayout(LayoutKind.Explicit, Pack = 0, Size = 63)]
public struct CarTelemetryData

    [FieldOffset(0)]
    public ushort m_speed;                    // Speed of car in kilometres per hour
    [FieldOffset(2)]
    public float m_throttle;                 // Amount of throttle applied (0.0 to 1.0)
    [FieldOffset(6)]
    public float m_steer;                    // Steering (-1.0 (full lock left) to 1.0 (full lock right))
    [FieldOffset(10)]
    public float m_brake;                    // Amount of brake applied (0.0 to 1.0)
    [FieldOffset(14)]
    public byte m_clutch;                   // Amount of clutch applied (0 to 100)
    [FieldOffset(15)]
    public sbyte m_gear;                     // Gear selected (1-8, N=0, R=-1)
    [FieldOffset(16)]
    public ushort m_engineRPM;                // Engine RPM
    [FieldOffset(18)]
    public byte m_drs;                      // 0 = off, 1 = on
    [FieldOffset(19)]
    public byte m_revLightsPercent;         // Rev lights indicator (percentage)
    [FieldOffset(20)]
    public UInt16Quad m_brakesTemperature;     // Brakes temperature (celsius)
    [FieldOffset(28)]
    public UInt16Quad m_tyresSurfaceTemperature; // Tyres surface temperature (celsius)
    [FieldOffset(36)]
    public UInt16Quad m_tyresInnerTemperature; // Tyres inner temperature (celsius)
    [FieldOffset(44)]
    public ushort m_engineTemperature;        // Engine temperature (celsius)
    [FieldOffset(46)]
    public SingleQuad tyresPressure;         // Tyres pressure (PSI)
    [FieldOffset(62)]
    public ByteQuad m_surfaceType;           // Driving surface, see appendice
;
[StructLayout(LayoutKind.Explicit, Pack = 0, Size = 8)]
public struct UInt16Quad

    [FieldOffset(0)]
    public ushort A;
    [FieldOffset(2)]
    public ushort B;
    [FieldOffset(6)]
    public ushort C;
    [FieldOffset(6)]
    public ushort D;

[StructLayout(LayoutKind.Explicit, Pack = 0, Size = 16)]
public struct SingleQuad

    [FieldOffset(0)]
    public float A;
    [FieldOffset(4)]
    public float B;
    [FieldOffset(8)]
    public float C;
    [FieldOffset(12)]
    public float D;

[StructLayout(LayoutKind.Explicit, Pack = 0, Size = 4)]
public struct ByteQuad

    [FieldOffset(0)]
    public byte A;
    [FieldOffset(1)]
    public byte B;
    [FieldOffset(2)]
    public byte C;
    [FieldOffset(3)]
    public byte D;

static class P

    static void Main()
    
        Console.WriteLine(Unsafe.SizeOf<PacketHeader>());
        Console.WriteLine(Unsafe.SizeOf<CarTelemetryData>());
        Console.WriteLine(bytes.Length);
        ReadOnlySpan<byte> remaining = bytes;
        var header = MemoryMarshal.Cast<byte, PacketHeader>(remaining)[0];
        remaining = remaining.Slice(Unsafe.SizeOf<PacketHeader>());
        Console.WriteLine($"header.m_packetFormat header.m_gameMajorVersion, header.m_gameMinorVersion: header.m_packetId");
        switch (header.m_packetId)
        
            case PacketType.CarTelemetry:
                // we expect 20*CarTelemetryData, then a uint of the buttons
                // note we *could* use a fixed buffer for this, but... that's really very
                // awkward to work with; let's try this instead
                int carIndex = 0;
                foreach (var telemetry in MemoryMarshal.Cast<byte, CarTelemetryData>(remaining).Slice(0, 20))
                
                    Console.WriteLine($"car: carIndex, speed: telemetry.m_speed, throttle: telemetry.m_throttle");
                    var temps = telemetry.m_tyresInnerTemperature;
                    Console.WriteLine($"  type temps: temps.A/temps.B/temps.C/temps.D");
                
                remaining = remaining.Slice(20 * Unsafe.SizeOf<CarTelemetryData>());
                var buttons = MemoryMarshal.Cast<byte, uint>(remaining)[0];
                Console.WriteLine($"Buttons: buttons");
                remaining = remaining.Slice(sizeof(uint));
                Console.WriteLine($"Unaccounted for: remaining.Length");
                break;
        

    

    static readonly byte[] bytes = new byte[] 
        0xE3, 0x07, 0x01, 0x15, 0x01, 0x06, 0xF8, 0xCE, 0xBE, 0x09, 0x64, 0x7F, 0xEA, 0xD1, 0xDC, 0xA1, 0x16, 0x41, 0x91, 0x01, 0x00, 0x00, 0x13, 0x7B, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x36, 0x53, 0x7E, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xF3, 0x2F, 0x00, 0x64, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x74, 0x00, 0x74, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x1B, 0xF2, 0x3A, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x35, 0x2D, 0x00, 0x22, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x69, 0x00, 0x69, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xF3, 0x59, 0xA1, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x59, 0x2F, 0x00, 0x64, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x72, 0x00, 0x72, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xFE, 0x5F, 0x3F, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3D, 0x2E, 0x00, 0x3E, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x71, 0x00, 0x71, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x89, 0x78, 0x23, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x28, 0x00, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x77, 0x00, 0x78, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xC3, 0x73, 0x98, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x2F, 0x2E, 0x00, 0x54, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x75, 0x00, 0x75, 0x00, 0x50, 0x00, 0x4F, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xF3, 0xF4, 0xBA, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x21, 0x2E, 0x00, 0x59, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x75, 0x00, 0x75, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x4D, 0x7D, 0x04, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFB, 0x2F, 0x00, 0x64, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x70, 0x00, 0x70, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x75, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x84, 0x45, 0xAB, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xBF, 0x2D, 0x00, 0x31, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x77, 0x00, 0x77, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xB5, 0x8C, 0xBD, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1B, 0x28, 0x00, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x71, 0x00, 0x71, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xF8, 0xD0, 0x87, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x63, 0x2C, 0x00, 0x37, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x79, 0x00, 0x79, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xFF, 0xA7, 0x60, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xDE, 0x2F, 0x00, 0x64, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x6E, 0x00, 0x6E, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xB9, 0x2E, 0x2F, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xD1, 0x2F, 0x00, 0x64, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x75, 0x00, 0x75, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xCD, 0x1E, 0x18, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3F, 0x2D, 0x00, 0x23, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x6F, 0x00, 0x6F, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x15, 0x0F, 0xAF, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xA5, 0x2B, 0x00, 0x0C, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x70, 0x00, 0x70, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x2B, 0xC0, 0x14, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x49, 0x2F, 0x00, 0x64, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x6F, 0x00, 0x6F, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x41, 0xCA, 0xC0, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x85, 0x2B, 0x00, 0x64, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x79, 0x00, 0x79, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x07, 0x1F, 0xD5, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xDE, 0x2A, 0x00, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x78, 0x00, 0x78, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5B, 0x00, 0x5B, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x80, 0x3F, 0xDD, 0xC0, 0x1C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xDD, 0x2A, 0x00, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x6F, 0x00, 0x6F, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x5A, 0x00, 0x5A, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xAC, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0xB8, 0x41, 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x97, 0x96, 0x96, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x9B, 0x17, 0x00, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x1D, 0x00, 0x62, 0x00, 0x62, 0x00, 0x4F, 0x00, 0x4F, 0x00, 0x59, 0x00, 0x59, 0x00, 0x58, 0x00, 0x58, 0x00, 0x5A, 0x00, 0xCD, 0xCC, 0xA8, 0x41, 0xCD, 0xCC, 0xA8, 0x41, 0x33, 0x33, 0xBB, 0x41, 0x33, 0x33, 0xBB, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00;

【讨论】:

以上是关于构造UDP数据包的字节数组的主要内容,如果未能解决你的问题,请参考以下文章

00106_UDP通信

需要将字节数组/二进制消息从 UDP DatagramPacket 转换为 java 中的几个字段

如何构造一个包含多种数据类型值的字节数组?

如果我在 C# 中发送 0 有效载荷数据,udp 数据包的大小是多少?

在 C# 中使用字节数组

浅谈UDP(数据包长度,收包能力,丢包及进程结构选择)