Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

random_port

Find a random available TCP port


Description

Test a series of random TCP ports from 3000 to 8000 (excluding a few that are considered unsafe by Chrome) and return the first available one. A web server can be later started on this port.

Usage

random_port(port = 4321L, host = getOption("servr.host", "127.0.0.1"), n = 20)

Arguments

port

The preferred port(s).

host

A string that is a valid IPv4 address that is owned by this server, or "0.0.0.0" to listen on all IP addresses.

n

The maximum number of random ports to be tested.

Value

A port number, or an error if no ports are available.


servr

A Simple HTTP Server to Serve Static Files or Dynamic Documents

v0.22
GPL
Authors
Yihui Xie [aut, cre] (<https://orcid.org/0000-0003-0645-5666>), Carson Sievert [ctb], Jesse Anderson [ctb], Ramnath Vaidyanathan [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.