javascript node.js v0.4.x和v0.6.x之间广播和多播兼容性的简单测试用例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript node.js v0.4.x和v0.6.x之间广播和多播兼容性的简单测试用例相关的知识,希望对你有一定的参考价值。
var dgram = require('dgram');
var socket = dgram.createSocket('udp4');
var testMessage = "[hello world] pid: " + process.pid;
var multicastAddress = '239.1.2.3'
var multicastPort = 5554
socket.addMembership(multicastAddress);
socket.bind(multicastPort, '0.0.0.0');
socket.on("message", function ( data, rinfo ) {
console.log("Message received from ", rinfo.address, " : ", data.toString());
});
setInterval(function () {
socket.send(new Buffer(testMessage),
0,
testMessage.length,
multicastPort,
multicastAddress,
function (err) {
if (err) console.log(err);
console.log("Message sent");
}
);
}, 1000);
var dgram = require('dgram');
var socket = dgram.createSocket('udp4');
var testMessage = "[hello world] pid: " + process.pid;
var broadcastAddress = '255.255.255.255';
var broadcastPort = 5555;
socket.setBroadcast(true);
socket.bind(broadcastPort, '0.0.0.0');
socket.on("message", function ( data, rinfo ) {
console.log("Message received from ", rinfo.address, " : ", data.toString());
});
setInterval(function () {
socket.send(new Buffer(testMessage),
0,
testMessage.length,
broadcastPort,
broadcastAddress,
function (err) {
if (err) console.log(err);
console.log("Message sent");
}
);
}, 1000);
以上是关于javascript node.js v0.4.x和v0.6.x之间广播和多播兼容性的简单测试用例的主要内容,如果未能解决你的问题,请参考以下文章
node.js 初识node.js,运行在服务端的 JavaScript
如何系统地学习Node.js?
Node.js一学习一
Node.js 入门:就是运行在服务端的 JavaScript
node.js初步
Node.js 简介