Learn R Programming

⚠️There's a newer version (1.10.2) of this package.Take me there.

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

52,961

Version

1.8.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Charlie Gao

Last Published

April 4th, 2026

Functions in nanonext (1.8.2)

listen

Listen to an Address from a Socket
messenger

Messenger
mclock

Clock Utility
handler_redirect

Create HTTP Redirect Handler
http_server

Create HTTP/WebSocket Server
handler_ws

Create WebSocket Handler
is_aio

Validators
handler_stream

Create HTTP Streaming Handler
is_error_value

Error Validators
ip_addr

IP Address
nano

Create Nano Object
ncurl_session

ncurl Session
nng_error

Translate Error Codes
monitor

Monitor a Socket for Pipe Changes
msleep

Sleep Utility
nanonext-package

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

ncurl
nng_version

NNG Library Version
ncurl_aio

ncurl Async
opt

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

Receive
protocols

Protocols (Documentation)
pipe_notify

Pipe Notify
recv_aio

Receive Async
parse_url

Parse URL
reap

Reap
race_aio

Race Aio
read_stdin

Read stdin
random

Random Data Generation
pipe_id

Get the Pipe ID of a recvAio
stat

Get Statistic for a Socket, Listener or Dialer
status_code

Translate HTTP Status Codes
request

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

Send
socket

Open Socket
start

Start Listener/Dialer
send_aio

Send Async
serial_config

Create Serialization Configuration
stop_aio

Stop Asynchronous Aio Operation
reply

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

Write to Stdout
zzz

Internal Package Function
subscribe

Subscribe / Unsubscribe Topic
unresolved

Query if an Aio is Unresolved
stream

Open Stream
survey_time

Set Survey Time
tls_config

Create TLS Configuration
stop_request

Stop Request Operation
transports

Transports (Documentation)
write_cert

Generate Self-Signed Certificate and Key
cv

Condition Variables
as.promise.recvAio

Make recvAio Promise
call_aio

Call the Value of an Asynchronous Aio Operation
context

Open Context
.advance

Advances the RNG State
close.nanoContext

Close Connection
collect_aio

Collect Data of an Aio or List of Aios
dial

Dial an Address from a Socket
as.promise.ncurlAio

Make ncurlAio Promise
handler_directory

Create Static Directory Handler
handler_inline

Create Inline Static Content Handler
%~>%

Signal Forwarder
handler_file

Create Static File Handler
handler

Create HTTP Handler
format_sse

Format Server-Sent Event
.dispatcher

Dispatcher
.mark

Set Serialization Marker
.keep

Keep Promise
.context

Technical Utility: Open Context
.unresolved

Technical Utility: Query if an Aio is Unresolved