peer-network

Create servers/clients that listen on names instead of ports and hostnames and are accessible over the internet

Github星跟蹤圖

peer-network

Create servers/clients that listen on names instead of ports and hostnames and are accessible over the internet.
Uses hyperdht to discover peers and holepunch connections to them.

Per default it uses bootstrap1.hyperdht.org to bootstrap the DHT but you can configure your own.

npm install peer-network

build status

Usage

First create a server

var peernet = require('peer-network')
var network = peernet()

var server = network.createServer()

server.on('connection', function (stream) {
  console.log('new connection')
  stream.pipe(stream) // echo
})

server.listen('echo-server') // listen on a name

In another process (on any machine)

// will connect to a server annoucing itself as echo-server
var stream = network.connect('echo-server')

stream.write('hello world')
stream.on('data', function (data) {
  console.log('data:', data.toString())
})

API

var network = peernet(opts)

Create a new network instance. Options are forwarded to the hyperdht constructor.
If you do not provide a bootstrap list, bootstrap1.hyperdht.org is used.

var server = network.createServer([onconnection])

Create a new server.

server.listen(name, [onlistening])

Listen on a name. Can be any buffer/string. Optionally you can specify a port to bound to as well. If not specified a random open port will be used.
The server will use discovery-channel to announce itself to other peers using multicast-dns, the bittorrent dht and potentially a series of dns servers.

server.close([onclose])

Close the server and stop announcing its pressence

server.on('connection', stream)

Emitted when a client connects

server.on('listening')

Emitted when the server is listening.

server.on('error', err)

Emitted if the server has a critical error.

server.on('close')

Emitted when the server is fully close

var stream = network.connect(name)

Connect to a server listening on a name. If multiple servers are listening it will connect to the first one to which an connection can be established.

stream.on('connect')

Emitted when the stream is fully connected to another peer. You do not need to wait for this event before writing data to the socket.

License

MIT

主要指標

概覽
名稱與所有者mafintosh/peer-network
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2016-08-08 13:03:17
推送於2017-04-22 11:47:03
最后一次提交2017-04-22 13:46:31
發布數7
最新版本名稱v2.0.2 (發布於 2017-04-22 13:40:29)
第一版名稱v1.0.0 (發布於 2016-08-08 15:03:50)
用户参与
星數184
關注者數7
派生數18
提交數20
已啟用問題?
問題數4
打開的問題數2
拉請求數1
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?