Learn R Programming

nanonext

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

  • Scalability protocols - pub/sub, req/rep, push/pull, surveyor/respondent, bus, pair
  • Multiple transports - TCP, IPC, WebSocket, TLS, in-process
  • Async I/O - non-blocking operations with auto-resolving ‘aio’ objects
  • Cross-language - exchange data with Python, C++, Go, Rust
  • Web toolkit - unified HTTP, WebSocket, and streaming (SSE, NDJSON) on a single port

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

GuideTopics
Quick ReferenceAt-a-glance API overview
MessagingCross-language, async, synchronisation
Protocolsreq/rep, pub/sub, surveyor/respondent
ConfigurationTLS, options, serialization
Web ToolkitHTTP 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.

Links

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.

Copy Link

Version

Install

install.packages('nanonext')

Monthly Downloads

49,154

Version

1.8.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Charlie Gao

Last Published

February 9th, 2026

Functions in nanonext (1.8.0)

.read_header

Serialization Headers and Markers
handler

Create HTTP Handler
%~>%

Signal Forwarder
handler_directory

Create Static Directory Handler
ip_addr

IP Address
pipe_notify

Pipe Notify
.dispatcher

Dispatcher
close.nanoContext

Close Connection
call_aio

Call the Value of an Asynchronous Aio Operation
protocols

Protocols (Documentation)
transports

Transports (Documentation)
tls_config

Create TLS Configuration
handler_stream

Create HTTP Streaming Handler
.keep

Keep Promise
handler_redirect

Create HTTP Redirect Handler
handler_inline

Create Inline Static Content Handler
handler_file

Create Static File Handler
.advance

Advances the RNG State
.context

Technical Utility: Open Context
is_aio

Validators
.unresolved

Technical Utility: Query if an Aio is Unresolved
stat

Get Statistic for a Socket, Listener or Dialer
reap

Reap
ncurl_aio

ncurl Async
ncurl

ncurl
start

Start Listener/Dialer
read_stdin

Read stdin
mclock

Clock Utility
nng_version

NNG Library Version
messenger

Messenger
opt

Get and Set Options for a Socket, Context, Stream, Listener or Dialer
parse_url

Parse URL
pipe_id

Get the Pipe ID of a recvAio
handler_ws

Create WebSocket Handler
race_aio

Race Aio
random

Random Data Generation
nng_error

Translate Error Codes
http_server

Create HTTP/WebSocket Server
ncurl_session

ncurl Session
send

Send
listen

Listen to an Address from a Socket
is_error_value

Error Validators
msleep

Sleep Utility
monitor

Monitor a Socket for Pipe Changes
status_code

Translate HTTP Status Codes
subscribe

Subscribe / Unsubscribe Topic
write_stdout

Write to Stdout
zzz

Internal Package Function
send_aio

Send Async
survey_time

Set Survey Time
nano

Create Nano Object
stop_aio

Stop Asynchronous Aio Operation
reply

Reply over Context (RPC Server for Req/Rep Protocol)
nanonext-package

nanonext: NNG (Nanomsg Next Gen) Lightweight Messaging Library
socket

Open Socket
recv_aio

Receive Async
recv

Receive
stop_request

Stop Request Operation
stream

Open Stream
unresolved

Query if an Aio is Unresolved
write_cert

Generate Self-Signed Certificate and Key
request

Request over Context (RPC Client for Req/Rep Protocol)
serial_config

Create Serialization Configuration
cv

Condition Variables
as.promise.recvAio

Make recvAio Promise
collect_aio

Collect Data of an Aio or List of Aios
context

Open Context
dial

Dial an Address from a Socket
as.promise.ncurlAio

Make ncurlAio Promise
format_sse

Format Server-Sent Event