nng
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | networking ffi |
| Keywords | nng nanomsg messaging ipc pubsub reqrep |
NNG (nanomsg-next-gen) lightweight messaging library bindings for Kit
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
c/kit_nng.c | C FFI wrapper |
c/kit_nng.h | C header for FFI wrapper |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata and dependencies |
src/nng.kit | Kit NNG - Lightweight brokerless messaging library bindings |
tests/nng.test.kit | Tests for nng |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-nng.gitSystem Requirements
| Platform | Command |
|---|---|
| macOS | brew install nng |
| Ubuntu | sudo apt install libnng-dev |
| Fedora | sudo dnf install nng-devel |
Usage
import Kit.NNG as Nng
main = fn =>
# Pair pattern (bidirectional)
match Nng.pair-open
| Ok server ->
match Nng.listen server "ipc:///tmp/kit-nng-test"
| Ok _ ->
match Nng.pair-open
| Ok client ->
match Nng.dial client "ipc:///tmp/kit-nng-test"
| Ok _ ->
# Client sends, server receives
match Nng.send client "Hello!"
| Ok _ -> println "Sent"
| Err e -> println ("Send error: " ++ e)
msg = Nng.recv server
println ("Received: " ++ msg)
match Nng.close client
| Ok _ -> no-op
| Err _ -> no-op
| Err e -> println ("Dial error: " ++ e)
| Err e -> println ("Client error: " ++ e)
match Nng.close server
| Ok _ -> no-op
| Err _ -> no-op
| Err e -> println ("Listen error: " ++ e)
| Err e -> println ("Server error: " ++ e)
mainDevelopment
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis installs the package to ~/.kit/packages/@kit/nng/, making it available for import as Kit.NNG in other projects.
License
This package is released under the MIT License - see LICENSE for details.
NNG is released under the MIT License.
Exported Functions & Types
req-open
Open a REQ (request) socket for request/reply pattern.
Returns:
Result Ptr String
rep-open
Open a REP (reply) socket for request/reply pattern.
Returns:
Result Ptr String
pub-open
Open a PUB (publisher) socket for pub/sub pattern.
Returns:
Result Ptr String
sub-open
Open a SUB (subscriber) socket for pub/sub pattern.
Returns:
Result Ptr String
push-open
Open a PUSH socket for pipeline pattern (send side).
Returns:
Result Ptr String
pull-open
Open a PULL socket for pipeline pattern (receive side).
Returns:
Result Ptr String
pair-open
Open a PAIR socket for bidirectional one-to-one communication.
Returns:
Result Ptr String
bus-open
Open a BUS socket for many-to-many communication.
Returns:
Result Ptr String
close
Close a socket and free its resources.
Parameters:
Returns:
Ptr -> Result Unit String
listen
Start listening for connections on a URL.
Parameters:
Returns:
Ptr -> NonEmptyString -> Result Unit String
dial
Connect to a remote URL.
Parameters:
Returns:
Ptr -> NonEmptyString -> Result Unit String
send
Send a string message on the socket.
Parameters:
Returns:
Ptr -> String -> Result Unit String
recv
Receive a string message from the socket (blocking).
Parameters:
Returns:
Ptr -> String
recv-timeout
Receive a string message with a timeout.
Parameters:
Returns:
Ptr -> PositiveInt -> Option String
sub-subscribe
Subscribe to a topic on a SUB socket.
Parameters:
Returns:
Ptr -> String -> Result Unit String
sub-unsubscribe
Unsubscribe from a topic on a SUB socket.
Parameters:
Returns:
Ptr -> String -> Result Unit String
set-recv-timeout
Set the receive timeout for a socket.
Parameters:
Returns:
Ptr -> PositiveInt -> Result Unit String
set-send-timeout
Set the send timeout for a socket.
Parameters:
Returns:
Ptr -> PositiveInt -> Result Unit String
version
Get the NNG library version string.
Returns:
String