explaingit

nanomsg/nng

4,583CAudience · developerComplexity · 4/5LicenseSetup · moderate

TLDR

A C library that helps separate programs send messages to each other over a network using common patterns like publish-subscribe or request-reply, without writing low-level socket code.

Mindmap

mindmap
  root((NNG))
    Messaging patterns
      Publish subscribe
      Request reply
      Push pull
    Transport options
      TCP network
      In-process zero copy
      WebSockets
      TLS encrypted
    Platforms
      Linux macOS Windows
      Android iOS FreeBSD
    Build
      C11 compiler
      CMake required
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Use the publish-subscribe pattern to broadcast sensor readings from one source to many worker processes without managing individual connections.

USE CASE 2

Build a request-reply server in C where client programs send a question over TCP and get a response back, like a lightweight remote procedure call.

USE CASE 3

Distribute work items across a pool of worker processes using the push-pull pattern for parallel processing without a message broker.

USE CASE 4

Use TLS transport to encrypt messages between services running on an untrusted network.

Tech stack

CCMakeTLSWebSocketsTCP

Getting it running

Difficulty · moderate Time to first run · 1h+

Build requires CMake and a C11 compiler, TLS support requires an additional TLS library such as mbedTLS or wolfSSL.

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

NNG is a C library that helps separate programs communicate with each other over a network, or across different threads and processes on the same machine. It handles the low-level work of connecting, reconnecting on failure, managing message queues, and routing data, so the application code can focus on what to send rather than how to send it. The library is built around a set of well-established messaging patterns. Publish-subscribe lets one sender broadcast messages to many receivers without knowing who they are. Request-reply lets a client send a question and wait for an answer, like a simple remote procedure call. Push-pull distributes work items across a pool of workers. These patterns cover the most common ways distributed software components need to talk to each other. NNG is a rewrite of an older library called nanomsg, designed to be more reliable and to scale across multiple CPU cores. Internally it uses an asynchronous event system and a thread pool so it can handle many simultaneous connections without creating one thread per connection, which would hit system limits quickly. Applications built on the original nanomsg or on a Go port called mangos can talk directly to NNG applications over the network because the wire protocol is the same. Transport options include standard TCP, in-process pipes for zero-copy communication within a single program, inter-process communication via sockets on the local machine, WebSockets, and TLS-encrypted connections for secure communication. TLS support means credentials and data can be protected in transit when running over an untrusted network. The library builds with a standard C11 compiler and CMake on Linux, macOS, Windows, FreeBSD, Android, iOS, and several other platforms. It is designed to be embedded directly into other applications and is available under the MIT license.

Copy-paste prompts

Prompt 1
Show me a minimal NNG publish-subscribe example in C where a publisher sends a string and multiple subscribers receive it over TCP.
Prompt 2
How do I set up TLS-encrypted connections in NNG so my client and server communicate securely over an untrusted network?
Prompt 3
I'm migrating from the old nanomsg C library to NNG. What are the main API differences I need to update in my existing code?
Prompt 4
Show me how to use NNG's request-reply pattern to build a simple round-robin load balancer where multiple workers handle requests in turn.
Open on GitHub → Explain another repo

← nanomsg on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.