Skip to content

timhudson/listen-connect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published