How does nodejs send a binary structure over socket? The receiver is a c program

net: is intended to be used in nodejs

var net = require("net");

send such a structure to the peer:

typedef struct msg_head{
    unsigned int type;
    unsigned int len;
    int state;
}msg_head;

how should the data sent be organized?

Mar.18,2021

it is recommended that you first determine with the receiver their system architecture (32-bit / 64-bit), the compiler they use, and how they are deserialized.

for example, ask them how many bytes and sizes their unsigned int and int are, and then write data in the corresponding way of buffer .

Menu