首页 > 解决方案 > 如何使用 node.js 中的 ac 头文件解析 UDP 数据包

问题描述

我正在尝试连接从赛车模拟器读取 Telemtry 数据的服务器。

我一直在研究如何侦听 UDP 数据包,到目前为止,我已经成功地能够侦听客户端并接收数据包,然后记录 ArrayBuffer。

我遇到了这个 StackOvervflow 答案,它显示了如何解析它

javascript ArrayBuffer,它有什么用?

但是,我想知道是否有任何其他方式可以自动解析 C++ 头文件,或者我是否必须自己清理数据

这是我的 express node.js 服务器的示例

server.on("message", (buffer, rinfo) =>{
    console.log("received udp message")
    console.log(buffer)
})

这是 c++ 头文件的示例

enum EUDPStreamerPacketHandlerType
{
    eCarPhysics = 0,
    eRaceDefinition = 1,
    eParticipants = 2,
    eTimings = 3,
    eGameState = 4,
    eWeatherState = 5, // not sent at the moment, information can be found in the game state packet
    eVehicleNames = 6, //not sent at the moment
    eTimeStats = 7,
    eParticipantVehicleNames = 8
};

我想知道是否有人可以指出我正确的方向,我的谷歌搜索并没有变成太多,任何帮助将不胜感激

标签: javascriptc++node.js

解决方案


这是python代码

https://github.com/tyretrack/server/blob/91a0aba1ade8d3a45b53e5af432fb05a55703730/tyretrack/pcars/v2.py

您可以将其转换为所需的 javascript 代码。


推荐阅读