p2p-hub

所属分类:P2P编程
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2012-02-24 12:32:02
上 传 者sh-1993
说明:  json连接的对等中心,
(a peer to peer hub of json connections,)

文件列表:
examples/ (0, 2012-02-24)
examples/message-all-and-callback.js (857, 2012-02-24)
index.js (4736, 2012-02-24)
lib/ (0, 2012-02-24)
lib/peer.js (2929, 2012-02-24)
package.json (300, 2012-02-24)

# p2p-hub a super simple p2p hub that allows you to send json messages between computers ``` js var hub = require('p2p-hub').connect('json://address_to_a_member'); hub.on('connect', function(from) { console.log(from, 'connected'); // let's print all current nodes var all = hub.nodes(); console.log('all nodes:', all); // let's say hello to him hub.send(from, {hello:'world'}); }); hub.on('disconnect', function(from) { console.log(from, 'disconnected'); }); hub.on('message', function(from, message) { console.log(from, 'says', message); }); hub.send('json://another_member', {hello:'world'}); ``` You can also multiplex messages to support multiple apps on the same hub ``` js var hub = require('p2p-hub').connect('json://address_to_a_member'); var app = hub.multiplex('app'); app.on('connect', function(from) { console.log(from, 'connected to app'); console.log('all in app:', app.nodes()); }); app.on('disconnect', function(from) { console.log(from, 'disconnected from app'); }); app.on('message', function(from, message) { console.log(from, 'in app says', message); }); app.send('json://another_member', {hello:'app'}); ```

近期下载者

相关文件


收藏者