Create a POSIX socket.

socket_create(
  domain = c("inet", "inet6", "unix"),
  type = c("stream", "dgram"),
  protocol = 0L,
  nonblocking = FALSE,
  cloexec = TRUE
)

socket_bind(socket, address = NULL, port = NULL)

socket_listen(socket, backlog = 128L)

socket_accept(socket, nonblocking = NULL)

socket_connect(socket, address, port = NULL)

Arguments

domain

Address family: "inet", "inet6", or "unix".

type

Socket type: "stream" or "dgram".

protocol

Numeric protocol, usually zero.

nonblocking

Whether the accepted socket should be nonblocking; NULL inherits the listener mode.

cloexec

Whether to set close-on-exec.

socket

A socketR socket handle.

address

A hostname, IP address, or Unix-domain path.

port

A port between 0 and 65535; NULL for Unix sockets.

backlog

Maximum pending connection queue length.

Value

A socketR external-pointer handle.

Invisibly, the socket handle.

Invisibly, the socket handle.

A socket handle, or NULL when no connection is pending.

TRUE when connected, or FALSE when connection is in progress.

Examples

if (.Platform$OS.type != "windows") {
  s <- socket_create()
  socket_close(s)
}