listen-connect

3.0.0 • Public • Published

listen-connect

listen and connect methods for exposing a duplex stream to the network

build status

This was extracted from dnode

Example

var listenConnect = require('listen-connect')
 
rpcServer.listen = listenConnect.createListen(rpcServer.createStream)
rpcClient.connect = listenConnect.createConnect(rpcClient.createStream)
 
rpcServer.listen(4000, function() {
  console.log('RPC server listening on port 4000')
})
 
rpcClient.connect(4000, function() {
  console.log('RPC client connected to 4000')
})
 

Usage

port/host/path arguments parsed with parse-connection-args

listenConnect.createListen(fn)

Returns a listen function that accepts port/host/path arguments. When called it will create a new server with net.createServer and expose the stream on the provided port/host/path.

var listen = listenConnect.createListen(function() {
  return someDuplexStream()
})
 
var server = listen(4000)
 
// Clean up server with close
server.close()

listenConnect.createConnect(fn)

Returns a connect function that accepts port/host/path arguments. When called it will create a new connection, with net.connect, to the provided port/host/path.

var connect = listenConnect.createConnect(function() {
  return someDuplexStream()
})
 
var client = connect('localhost:4000')
 
// Clean up client with destroy
client.destroy()

License

MIT

Package Sidebar

Install

npm i listen-connect

Weekly Downloads

1

Version

3.0.0

License

MIT

Last publish

Collaborators

  • timhudson