bind-easy
Easily create UDP sockets and TCP servers that bind to ports
Last updated 3 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install bind-easy 
SYNC missed versions from official npm registry.

bind-easy

Easily create UDP sockets and TCP servers that bind to ports.

npm install bind-easy

Usage

const bind = require('bind-easy')

// bind to any port
const server = await bind.tcp()

// try binding to a specific port, fallback to any
const server = await bind.tcp(8080)

// try binding to a range of ports, fallback to any
const server = await bind.tcp([8080, 8081, 8082])

// try binding to a range of ports, fallback to any
const server = await bind.tcp([8080, 8081, 8082])

// try binding to a range of ports, fail if that cannot be done
const server = await bind.tcp([8080, 8081, 8082], { allowAny: false })

// The same API applies for udp and dual mode

// try binding to a range of UDP ports, fallback to any
const socket = await bind.udp([8080, 8081, 8082])

// try binding to the same port for both a UDP socket and TCP server, fallback to any
const { server, socket } = await bind.dual(8080)

API

server = await bind.tcp([ports], [{ allowAny }])

Bind a TCP server. Pass a range of ports to try.

If none of the ports work, bind to a random free one unless allowAny is set. If only one port is specified, it will try nearby ports first.

socket = await bind.udp(...)

Same but for a UDP socket.

{ server, socket } = await bind.dual(...)

Same but for both a TCP server and UDP socket binding to the same port.

License

MIT

Current Tags

  • 1.1.2                                ...           latest (3 years ago)

6 Versions

  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |