您的位置:首页 > Web前端 > Node.js

spread extension for node.js

2010-08-25 08:29 465 查看
一直没有找到支持 spread 的 nodejs 库,周末的时候大致写了一个,基本满足需要 http://github.com/iwater/node-spread

 

var sys = require('sys'),
spread = require('../lib/spread');

var con = new spread.Connection();
con.on('connected', function(){

var self = this;
var i = 0;

console.log('connected');
self.join('NODE');

setInterval(function(){
var msg = 'NODE' + (i++);
console.log('send:' + msg);
self.multicast('NODE', msg);
}, 1000);

setInterval(function () {
var msg;
while((msg = self.readSync()) != undefined){
console.log('recv:' + msg);
}
}, 100);

});

con.on('error', function(){
console.log('error'+sys.inspect(arguments));

});

con.on('message', function(msg){
console.log(msg);
});

con.connect('4803@localhost', 'nodejs1');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  extension function node.js