freePort: Find a TCP port that can be opened

View source: R/ports.R

freePortR Documentation

Find a TCP port that can be opened

Description

Find a TCP port that can be opened

Usage

freePort(
  ports = 1024:65535,
  default = if (getRversion() >= "4.0.0") NA_integer_ else "random",
  randomize = TRUE
)

Arguments

ports

(integer vector, or character string) Zero or more TCP ports in [0, 65535] to scan. If "random", then a random set of ports is considered. If "auto", then the port given by environment variable R_PARALLEL_PORT is used, which may also specify random.

default

(integer) NA_integer_ or a port to returned if an available port could not be found. If "first", then ports[1]. If "random", then a random port among ports is used. If length(ports) == 0, then NA_integer_.

randomize

(logical) If TRUE, ports is randomly shuffled before searched. This shuffle does not forward the RNG seed.

Value

Returns an integer representing the first port among ports that can be opened. If none can be opened, then default is returned. If port querying is not supported, as in R (< 4.0.0), then default is returned.


parallelly documentation built on May 31, 2023, 5:46 p.m.