ScriptsSep 11, 2026·3 min read

nanomsg — Socket Library for Scalable Messaging Patterns

Build distributed systems with a simple C library that provides common messaging patterns like pub/sub, request/reply, and pipeline.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
nanomsg
Direct install command
npx -y tokrepo@latest install f2d8a647-ade5-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

nanomsg is a socket library written in C that provides several common communication patterns for building distributed systems. Created by Martin Sustrik (co-creator of ZeroMQ), it simplifies inter-process and network messaging with a POSIX-like API and built-in scalability protocols.

What nanomsg Does

  • Implements messaging patterns: PAIR, PIPELINE, REQ/REP, PUB/SUB, SURVEY, and BUS
  • Works over TCP, IPC (Unix sockets), in-process, and WebSocket transports
  • Provides automatic reconnection and load balancing across endpoints
  • Handles message framing, routing, and delivery semantics per protocol
  • Exposes a simple BSD socket-like C API (nn_socket, nn_send, nn_recv)

Architecture Overview

nanomsg uses a layered architecture with transports at the bottom (TCP, IPC, inproc, WebSocket) and scalability protocols on top. Each protocol defines its own routing and delivery semantics. The library runs an internal I/O thread pool that manages connections and message queuing asynchronously. The public API is synchronous by default with non-blocking options available via nn_poll or socket options.

Self-Hosting & Configuration

  • Build from source with CMake or install via system package managers
  • Link against libnanomsg in your C/C++ project with -lnanomsg
  • Set socket options for buffer sizes, timeouts, and reconnect intervals via nn_setsockopt
  • Bind a socket to listen on an address, or connect to a remote endpoint
  • Language bindings exist for Python, Go, Rust, Java, Ruby, Node.js, and more

Key Features

  • Seven built-in scalability protocols covering most messaging patterns
  • Transport-agnostic: switch between TCP, IPC, and inproc by changing the address string
  • Automatic reconnection on connection loss with configurable retry intervals
  • Zero-copy message API for high-throughput scenarios
  • Clean C API with no external dependencies beyond the C standard library

Comparison with Similar Tools

  • ZeroMQ — more mature ecosystem with more patterns and language bindings; nanomsg offers a cleaner API and pluggable transports
  • nng — the spiritual successor to nanomsg by the same author, with an async-first API
  • gRPC — RPC framework with code generation; nanomsg provides raw messaging patterns
  • NATS — server-based pub/sub; nanomsg is a brokerless peer-to-peer library

FAQ

Q: What is the difference between nanomsg and nng? A: nng (nanomsg-next-gen) is the successor project with a redesigned async API and better scalability. nanomsg remains stable and widely deployed.

Q: Does nanomsg require a message broker? A: No. nanomsg is fully brokerless. Peers connect directly to each other.

Q: Which transport should I use for local IPC? A: Use ipc:// for inter-process on the same host or inproc:// for threads within the same process.

Q: What license does nanomsg use? A: MIT license.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets