Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

C与node对于经UDP协议传输的Buffer数据的处理问题

$
0
0

遇到的问题是一台设备经UDP协议向服务器发送buffer类型的数据,本人使用的是nodejs,在对接受的buffer数据进行转string等操作时,无法获取到想要的数据,但是别人给的C的版本可以输出正常数据,但是本人学过的C基本忘完了,所以想请问下,对应的C操作,NODE需要进行什么样的操作,才能获取正常的数据 C语言的操作:

recvfrom(server_socket_fd, buffer, BUFFER_SIZE,0,(struct sockaddr*)&client_addr, &client_addr_length) //实现声明了一个buffer空间,函数接受到通过udp协议发送的数据之后存储到了buffer中
//对接受的数据进行处理
struct cliprobe_data {
        unsigned char Apmac[6];
        unsigned short int Vendorid;
        unsigned short int Reserved1;
        unsigned char Bssid[6];
        unsigned char Radiotype;
        unsigned char Channel;
        unsigned char Associated;
        unsigned char Messagetype;
        char Timestamp[14];
        unsigned short int Reserved2;
        unsigned char Mutype;
        unsigned short int Reserved3;
        char Rssi;
        unsigned short int Reserved4;
        unsigned char Noisefloor;
        unsigned short int Reserved5;
        unsigned char Datarate;
        unsigned char MPDUflags;
        unsigned char Mumac[6];
        unsigned short int Framecontrol;
        unsigned short int Sequencecontrol;
        unsigned short int Reserved6;
};
package_data = (struct cliprobe_data *) buffer;//相当于格式化了buffer?

Node的话,

serverSocket.on('message', function(msg, rinfo){
    console.log(msg)//buffer 类型
    console.log(msg.toString())//乱码
});

Viewing all articles
Browse latest Browse all 14821

Trending Articles