random_port: Find a random available TCP port

View source: R/app.R

random_portR Documentation

Find a random available TCP port

Description

Find an available TCP port, starting with port, then sampling from 3000–8000 (excluding ports known to be blocked by Chrome).

Usage

random_port(port = 4321L, n = 20L, exclude = NULL, error = TRUE)

Arguments

port

Default port to try first.

n

Number of additional random ports to try.

exclude

Integer vector of ports to exclude from the search.

error

Whether to signal an error (default) or return NULL when no port is found.

Value

An integer port number. When error = TRUE (default), signals an error if no port is found; when error = FALSE, returns NULL.


xfun documentation built on June 19, 2026, 9:06 a.m.