Javascript 通过套接字从C到节点JS的消息变形 我编写了一个C++程序,它向节点JS服务器发送消息。 string message; int iResult = send( socket, message.c_str(), (int)strlen(message.c_str()), 0 );

Javascript 通过套接字从C到节点JS的消息变形 我编写了一个C++程序,它向节点JS服务器发送消息。 string message; int iResult = send( socket, message.c_str(), (int)strlen(message.c_str()), 0 );,javascript,c++,sockets,Javascript,C++,Sockets,节点JS代码 net.createServer(function(sock) { // Add a 'data' event handler to this instance of socket sock.on('data', function(data) { console.log(data); }); // Add a 'close' event handler to this instance of socket sock.o

节点JS代码

net.createServer(function(sock) {

    // Add a 'data' event handler to this instance of socket
    sock.on('data', function(data) {

        console.log(data);

    });

    // Add a 'close' event handler to this instance of socket
    sock.on('close', function(data) {
        console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort);
    });

}).listen(PORT, HOST);
node JS服务器接收到消息,但是当I console.log接收到消息时,我会得到如下结果

<Buffer 31 7c 31 34>


可能是什么问题?我如何解决此问题?

您发送了什么?我正在发送一个
char*
。来自C++的消息看起来像“2×23”。基本上,只有4-5个字符被
|
分隔。这不是缓冲区中的内容吗?我不知道。但是如何将类似于
的内容转换为javscript中的原始字符串?“317C3134”.split(“”.map(函数(a){return string.fromCharCode(parseInt(a,16));})==[“1”、“|”、“1”、“4”],但我认为缓冲区也有一个toString()。。。所以,console.log(字符串(数据))我猜。。。