socket_listen_auto.RdCreates a stream listener, tries bind candidates in prefer order, and
returns the first listener that binds and listens successfully. When
address is NULL, the family wildcard ("::" or "0.0.0.0") is used.
This helper supports IPv4 and IPv6 stream sockets only. Unix-domain sockets
require an explicit filesystem path with socket_create() and
socket_bind().
socket_listen_auto(
address = NULL,
port = NULL,
backlog = 128L,
reuse_address = TRUE,
cloexec = TRUE,
prefer = c("inet6", "inet")
)A local hostname or IP address, or NULL for a wildcard.
A port between 0 and 65535, or NULL when embedded in a
bracketed endpoint such as "[::1]:12345".
Maximum pending connection queue length.
Whether to set SO_REUSEADDR before binding.
Whether to set close-on-exec.
Address families to try, in order.
A listening socketR handle.
listener <- socket_listen_auto(port = 0L, prefer = "inet")
socket_local_name(listener)
#> $family
#> [1] "inet"
#>
#> $address
#> [1] "0.0.0.0"
#>
#> $port
#> [1] 42557
#>
socket_close(listener)