C++ send UDP message to node.js UDP server has unrecognizable code -
my node.js udp server's code
var port = 515; var host = '127.0.0.1'; var dgram = require('dgram'); var server = dgram.createsocket('udp4'); server.on('listening', function () { var address = server.address(); console.log('udp server listening on ' + address.address + ":" + address.port); }); server.on('message', function (message, remote) { console.log(remote.address + ':' + remote.port +' - ' + message); }); server.bind(port, host);
and c++ client's code is:
word wversionrequested = makeword(1, 1); wsadata wsadata; int err = wsastartup(wversionrequested, &wsadata); if (err != 0) { return false; } if ( lobyte( wsadata.wversion) != 1 || hibyte( wsadata.wversion) != 1 ) { wsacleanup(); return false; } // server address srvaddress.sin_addr.s_un.s_addr = inet_addr(getprofileudphost()); srvaddress.sin_family = af_inet; srvaddress.sin_port = htons(getprofileudpport()); int udpsend(cstring& content, sockaddr* address) { socket sockclient = socket(af_inet, sock_dgram, 0); int result = sendto(sockclient, content, content.getlength()+1, 0, address, sizeof(sockaddr)); closesocket(sockclient); return result; }
when user sends characters "中文",the nodejs udp server receives " ".it gets unrecognizable code. nodejs code's encoding utf-8 , changing ansi same problem.