3.0.0 • Published 9 years ago

listen-connect v3.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

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

3.0.0

9 years ago

2.0.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago