关于UDP socket 接收到的数据转HEX的问题,
var dgram = require("dgram");
var server = dgram.createSocket("udp4");
server.on("message", function (msg, rinfo) {
console.log("server got: " + msg + " from " +
rinfo.address + ":" + rinfo.port);
});
server.on("listening", function () {
var address = server.address();
console.log("server listening " +
address.address + ":" + address.port);
});
server.bind(3210);
接收到的数据msg如何转为 hex? 谢谢
1 回复
通过
len = buf.write(msg, 0);
console.log(buf.toString('hex', 0, len));
解决了。