Socket
Book a DemoInstallSign in
Socket

peer-network

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peer-network

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

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

peer-network

Create servers/clients that listen on names instead of ports and hostnames and are accessible over the internet. Uses discovery-channel to discover peers.

npm install peer-network

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 discovery-channel.

var server = network.createServer([onconnection])

Create a new server.

server.listen(name, [port], [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.on('connection', stream)

Emitted when a client connects

server.address()

Similar to https://nodejs.org/api/net.html#net_server_address.

server.on('listening')

Emitted when the server is listening.

server.on('error', err)

Emitted if the server has a critical error.

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.

License

MIT

FAQs

Package last updated on 08 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts