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_aio("async request")

# 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)) run_event_loop(1000)
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

Uses a system ‘libnng’ >= v1.12.3 and ‘libmbedtls’ v3.x if present, otherwise compiles the bundled sources (libnng v1.12.3, libmbedtls v3.6.5) directly into the package - requiring only a C compiler.

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. The bundled libraries are compiled directly by Rtools - no additional tools are needed.

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

44,343

Version

1.10.3

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Charlie Gao

Last Published

September 23rd, 2026

Functions in nanonext (1.10.3)

device_aio

Device (Async)
collect_aio

Collect Data of an Aio or List of Aios
.keep

Keep Promise
.mark

Set Serialization Marker
.unresolved

Technical Utility: Query if an Aio is Unresolved
.suspend_interrupts

Suspend Interrupts
close.nanoContext

Close Connection
call_aio

Call the Value of an Asynchronous Aio Operation
as.promise.ncurlAio

Make ncurlAio Promise
as.promise.recvAio

Make recvAio Promise
msleep

Sleep Utility
.dispatcher_wait

Wait for N Daemon Connections
.dispatcher_try_gate

Dispatcher Try Gate
nano

Create Nano Object
dial

Dial an Address from a Socket
.advance

Advances the RNG State
.context

Technical Utility: Open Context
.dispatcher_capacity

Dispatcher Capacity
monitor

Monitor a Socket for Pipe Changes
mclock

Clock Utility
context

Open Context
nng_error

Translate Error Codes
handler_stream

Create HTTP Streaming Handler
handler_redirect

Create HTTP Redirect Handler
ip_addr

IP Address
.dispatcher_start

Start In-Process Dispatcher
.dispatcher_gate

Dispatcher Gate
read_stdin

Read stdin
random

Random Data Generation
nng_version

NNG Library Version
stop_aio

Stop Asynchronous Aio Operation
status_code

Translate HTTP Status Codes
handler_directory

Create Static Directory Handler
handler

Create HTTP Handler
subscribe

Subscribe / Unsubscribe Topic
handler_ws

Create WebSocket Handler
http_server

Create HTTP/WebSocket Server
pipe_notify

Pipe Notify
pipe_id

Get the Pipe ID of a recvAio
race_aio

Race Aio
protocols

Protocols (Documentation)
.dispatcher_stop

Stop In-Process Dispatcher
.dispatcher_info

Dispatcher Info
recv_aio

Receive Async
survey_time

Set Survey Time
ncurl_aio

ncurl Async
ncurl_session

ncurl Session
nanonext-package

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

Create Static File Handler
handler_inline

Create Inline Static Content Handler
is_error_value

Error Validators
ncurl

ncurl
stream

Open Stream
%~>%

Signal Forwarder
format_sse

Format Server-Sent Event
listen

Listen to an Address from a Socket
stop_request

Stop Request Operation
write_stdout

Write to Stdout
is_aio

Validators
zzz

Internal Package Function
run_event_loop

Run the Event Loop
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)
send

Send
send_aio

Send Async
serial_config

Create Serialization Configuration
socket

Open Socket
reply

Reply over Context (RPC Server for Req/Rep Protocol)
tls_config

Create TLS Configuration
stat

Get Statistic for a Socket, Listener or Dialer
recv

Receive
transports

Transports (Documentation)
reap

Reap
start

Start Listener/Dialer
parse_url

Parse URL
opt

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

Condition Variables