random-port

0.7.4last stable release 3 weeks ago
Complexity Score
Low
Open Issues
N/A
Dependent Projects
8
Weekly Downloadsglobal
197

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

Random TCP Port Generator for Ruby

It’s a simple Ruby gem to get a random TCP port.

First, install it:

gem install random-port

Then, use it like this, to reserve a random TCP port:

require 'random-port'
port = RandomPort::Pool.new.acquire

The Pool guarantees that the port won’t be used again. You can put the port back to the pool after usage:

RandomPort::Pool.new.acquire do |port|
  # Use the TCP port. It will be returned back
  # to the pool afterwards.
end

You can do it without the block:

pool = RandomPort::Pool.new
port = pool.acquire
pool.release(port)

You can also use a pre-defined Pool::SINGLETON singleton:

RandomPort::Pool::SINGLETON.acquire do |port|
  # Use it here...
end

The pool is thread-safe by default. You can configure it to be not-thread-safe, using optional sync argument of the constructor.

How to contribute

Read these guidelines. Make sure you build is green before you contribute your pull request. You will need to have Ruby 2.3+ and Bundler installed. Then:

bundle update
bundle exec rake

If it’s clean and you don’t see any error messages, submit your pull request.

Dependencies

No runtime dependency information found for this package.

CVE IssuesActive
0
Scorecards Score
No Data
Test Coverage
No Data
Follows Semver
Yes
Github Stars
17
Dependenciestotal
1
DependenciesOutdated
0
DependenciesDeprecated
0
Threat Modelling
No Data
Repo Audits
No Data

Learn how to distribute random-port in your own private RubyGems registry

gem install random-port
Processing...
Done

16 Releases

RubyGems on Cloudsmith

Getting started with RubyGems on Cloudsmith is fast and easy.