https://github.com/r-lib/nanonext
R binding for NNG (Nanomsg Next Gen)
https://github.com/r-lib/nanonext
concurrency https ipc-message messaging-library nng r rpc socket-communication synchronization-primitives tcp-protocol websocket
Last synced: 20 days ago
JSON representation
R binding for NNG (Nanomsg Next Gen)
- Host: GitHub
- URL: https://github.com/r-lib/nanonext
- Owner: r-lib
- License: other
- Created: 2022-01-23T12:59:16.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2026-03-05T14:16:22.000Z (24 days ago)
- Last Synced: 2026-03-05T17:50:57.719Z (24 days ago)
- Topics: concurrency, https, ipc-message, messaging-library, nng, r, rpc, socket-communication, synchronization-primitives, tcp-protocol, websocket
- Language: C
- Homepage: https://nanonext.r-lib.org/
- Size: 51.4 MB
- Stars: 79
- Watchers: 7
- Forks: 11
- Open Issues: 4
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
---
```{r}
#| include: false
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
[](https://CRAN.R-project.org/package=nanonext)
[](https://r-lib.r-universe.dev/nanonext)
[](https://github.com/r-lib/nanonext/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/r-lib/nanonext)
Fast, lightweight toolkit for messaging, concurrency, and the web in R. Built on [NNG (Nanomsg Next Gen)](https://nng.nanomsg.org/) 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
[](https://deepwiki.com/r-lib/nanonext)
### Quick Start
```{r}
#| label: quickstart
library(nanonext)
# Open sockets
s1 <- socket("req", listen = "ipc:///tmp/nanonext")
s2 <- socket("rep", dial = "ipc:///tmp/nanonext")
# Send
s1 |> send("hello world")
# Receive on the other
s2 |> recv()
close(s1)
close(s2)
```
### Async I/O
Non-blocking operations that resolve automatically:
```{r}
#| label: async
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")
# Async operations return immediately
aio <- recv_aio(s1)
aio
# Retrieve result when ready
aio$data
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.
```{r}
#| label: web
# 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
server$close()
```
### Documentation
| Guide | Topics |
|:------|:-------|
| [Quick Reference](https://nanonext.r-lib.org/articles/nanonext.html) | At-a-glance API overview |
| [Messaging](https://nanonext.r-lib.org/articles/v01-messaging.html) | Cross-language, async, synchronisation |
| [Protocols](https://nanonext.r-lib.org/articles/v02-protocols.html) | req/rep, pub/sub, surveyor/respondent |
| [Configuration](https://nanonext.r-lib.org/articles/v03-configuration.html) | TLS, options, serialization |
| [Web Toolkit](https://nanonext.r-lib.org/articles/v04-web.html) | HTTP client/server, WebSocket, streaming |
### Installation
```{r}
#| label: cran
#| eval: false
# 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:
```r
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](https://nanonext.r-lib.org/) |
[NNG](https://nng.nanomsg.org/) |
[Mbed TLS](https://www.trustedfirmware.org/projects/mbed-tls/) |
[CRAN HPC Task View](https://cran.r-project.org/view=HighPerformanceComputing) |
[CRAN Web Technologies](https://cran.r-project.org/view=WebTechnologies)
### Acknowledgements
- [Garrett D'Amore](https://github.com/gdamore) (NNG author) for advice and implementing features for nanonext
- [R Consortium](https://r-consortium.org/) for funding TLS development, with support from [Henrik Bengtsson](https://github.com/HenrikBengtsson) and [Will Landau](https://github.com/wlandau/)
- [Joe Cheng](https://github.com/jcheng5/) for prototyping event-driven promises integration
- [Luke Tierney](https://github.com/ltierney/) and [Mike Cheng](https://github.com/coolbutuseless) for R serialization documentation
- [Travers Ching](https://github.com/traversc) for novel ideas on custom serialization
- [Jeroen Ooms](https://github.com/jeroen) for the Anticonf configure script
--
Please note that this project is released with a [Contributor Code of Conduct](https://nanonext.r-lib.org/CODE_OF_CONDUCT.html). By participating in this project you agree to abide by its terms.
