Skip to main content

freeport 2.0.0 copy "freeport: ^2.0.0" to clipboard
freeport: ^2.0.0 copied to clipboard

A small, dependency-free Dart library for finding available TCP ports, with ordered preferred ports and hostname support.

2.0.0 #

Breaking changes #

  • Invalid port values and unsupported hostname argument types now throw ArgumentError; unexpected errors propagate instead of returning false.
  • Hostnames are resolved rather than silently replaced with IPv4 loopback. Use hostname: '127.0.0.1' explicitly if you need that address.
  • isAvailablePort(0) now performs a real bind and can return false.

Fixes and improvements #

  • Check preferred ports in order and close each probe before continuing.
  • Parse literal IP strings directly and reuse resolved addresses within each search to avoid repeated address lookups for occupied candidates.
  • Honor compile-time HOST configuration in compiled applications.
  • Document port reservation limits, address defaults, and error behavior.
  • Add deterministic regression tests and reduce CI to four OS/SDK combinations.

1.0.1 #

  • Fix handling of invalid port 0 in free port selection
  • Optimize preferred port selection to return first available

1.0.0 #

  • Remove unnecessary await from ServerSocket.bind call
  • Ensure socket is closed after getting port number
  • Optimize preferred port selection logic
  • Handle port 0 and simplify address resolution in freeport

0.0.2 #

Bug Fixes #

  • Fixed resource leak in isAvailablePort function by properly closing the Socket after port testing #2
  • Improved port testing logic to ensure network resources are released after checks

Improvements #

  • Implemented parallel port checking in freePort function for significant performance improvement when testing multiple preferred ports
  • Added two-stage port checking strategy with fallback mechanism for better reliability
  • Refactored the implementation of isAvailablePort function with better Future handling
  • Enhanced handling of port 0 logic

Credits #

  • Thanks to @FourLeafTec for submitting PR #2, fixing the Socket resource leak issue

0.0.1 #

  • Initial version.
3
likes
160
points
833
downloads

Documentation

Documentation
API reference

Publisher

verified publishermedz.dev

Weekly Downloads

A small, dependency-free Dart library for finding available TCP ports, with ordered preferred ports and hostname support.

Repository (GitHub)
View/report issues

Topics

#network #port #socket #utility

Funding

Consider supporting this project:

github.com

License

MIT (license)

More

Packages that depend on freeport