The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

nanonext nanonext logo

CRAN status R-universe status R-CMD-check Codecov test coverage

Fast, lightweight toolkit for messaging, concurrency, and the web in R. Built on NNG (Nanomsg Next Gen) and implemented almost entirely in C.

Quick Start

library(nanonext)

# Open sockets
s1 <- socket("req", listen = "ipc:///tmp/nanonext")
s2 <- socket("rep", dial = "ipc:///tmp/nanonext")

# Send
s1 |> send("hello world")
#> [1] 0

# Receive on the other
s2 |> recv()
#> [1] "hello world"

close(s1)
close(s2)

Async I/O

Non-blocking operations that resolve automatically:

s1 <- socket("rep", listen = "tcp://127.0.0.1:5556")
s2 <- socket("req", dial = "tcp://127.0.0.1:5556")

# Sender
s2 |> send("async request")
#> [1] 0

# Async operations return immediately
aio <- recv_aio(s1)
aio
#> < recvAio | $data >

# Retrieve result when ready
aio$data
#> [1] "async request"

close(s1)
close(s2)

Web Toolkit

One server, one port – HTTP endpoints, WebSocket connections, and streaming all coexist. Mbed TLS built in for HTTPS/WSS.

# Generate self-signed certificates
cert <- write_cert(cn = "127.0.0.1")

# HTTPS server (port 0 = auto-assign a free port)
server <- http_server(
  url = "https://127.0.0.1:0",
  handlers = list(
    handler("/", \(req) list(status = 200L, body = '{"status":"ok"}'))
  ),
  tls = tls_config(server = cert$server)
)
server$start()

# Async HTTPS client
aio <- ncurl_aio(server$url, tls = tls_config(client = cert$client))
while (unresolved(aio)) later::run_now(1)
aio$data
#> [1] "{\"status\":\"ok\"}"

server$close()

Documentation

Guide Topics
Quick Reference At-a-glance API overview
Messaging Cross-language, async, synchronisation
Protocols req/rep, pub/sub, surveyor/respondent
Configuration TLS, options, serialization
Web Toolkit HTTP client/server, WebSocket, streaming

Installation

# CRAN
install.packages("nanonext")

# Development version
install.packages("nanonext", repos = "https://r-lib.r-universe.dev")

Building from Source

Linux / Mac / Solaris

Requires ‘libnng’ >= v1.9.0 and ‘libmbedtls’ >= 2.5.0, or ‘cmake’ to compile bundled libraries (libnng v1.11.0, libmbedtls v3.6.5).

Recommended: Let the package compile bundled libraries for optimal performance:

Sys.setenv(NANONEXT_LIBS = 1)
install.packages("nanonext")

System packages: libnng-dev / nng-devel, libmbedtls-dev / libmbedtls-devel. Set INCLUDE_DIR and LIB_DIR for custom locations.

Windows

Requires Rtools. For R >= 4.2, cmake is included. Earlier versions need cmake installed separately and added to PATH.

Documentation | NNG | Mbed TLS | CRAN HPC Task View | CRAN Web Technologies

Acknowledgements

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.