Last updated

🔗Examples

Every example lives in examples/ and is runnable as-is. Each one has its own page here with the complete source pasted in and a walkthrough of the interesting parts. Ignore prebuilt binaries in examples/; only the .nim sources matter.

🔗HTTP servers

ExampleDemoPage
httpserver.nimTiny HTTP/1.1 server, manual routinghttpserver
httpserver_threads.nimOne loop per core via SO_REUSEPORThttpserver_threads
static_server.nimStatic site + CORS + JSON APIstatic_server
stream_server.nimstreamFile / sendFile / serveFile, Range & resumestream_server
upload_server.nimRaw-body and multipart uploadsupload_server
uds_server.nimHTTP over a Unix domain socketuds_server
tls_server.nimHTTPS with an embedded self-signed certtls_server

🔗Clients

ExampleDemoPage
httpclient.nimSync + async HTTP client, pooling, UDShttpclient

🔗WebSocket

ExampleDemoPage
wsserver.nimStandalone WebSocket serverwsserver
wsclient.nimHigh-level client: reconnect, sendMessagewsclient
wsupgrade.nimHTTP and WebSocket on one portwsupgrade
ws_chat.nimMulti-client chat with broadcastws_chat

🔗TCP

ExampleDemoPage
tcp_chat.nimMulti-client chat room on raw TCPtcp_chat
tcp_client.nimInteractive stdin client for the chattcp_client
tcp_proxy.nimReverse proxy / load balancer with connect bufferingtcp_proxy

🔗UDP and DTLS

ExampleDemoPage
udp_echo.nimUDP echo server plus ping client modeudp_echo
dtls_echo.nimDTLS 1.2 echo with cookie exchange and MTU splittingdtls_echo

🔗Core features

ExampleDemoPage
timers_scheduler.nimTimer wheel: one-shot, interval, deferred, idletimers_scheduler
fswatch.nimFile system watcher eventsfswatch
os_signals.nimGraceful shutdown on SIGINT / SIGTERMos_signals
signal_bus.nimIn-process pub/sub SignalRelaysignal_bus
stream_pipe.nimIoStream socketpair echo with EOFstream_pipe
ratelimit_server.nimSliding-window per-IP rate limitingratelimit

🔗Port map

PortExample
9000httpserver, httpserver_threads, wsupgrade, upload_server
9001wsserver
9002stream_server (needs the ~2.76 GB .webm)
9003ratelimit_server
9004static_server
9005signal_bus
9006ws_chat
9007os_signals
9010tcp_chat and tcp_client
9011udp_echo
9012dtls_echo
9020 / 9021tcp_proxy and its backend
9443tls_server
nonetimers_scheduler, fswatch, stream_pipe, httpclient
UDS pathuds_server ( /tmp/powpow.sock)

🔗Quick smoke test

# HTTP server
curl http://localhost:9000/
curl http://localhost:9000/api/echo -d 'Hello powpow!'

# WebSocket
websocat ws://localhost:9001          # or: npx wscat -c ws://localhost:9001

# TCP chat
nc 127.0.0.1 9010

# UDP
echo "hello udp" | nc -u -w1 127.0.0.1 9011
nim c -r examples/udp_echo.nim -- --client

# TLS and DTLS
curl -k https://localhost:9443/hello
nim c -r examples/dtls_echo.nim -- --client

# UDS
curl --unix-socket /tmp/powpow.sock http://localhost/hello

# Rate limiting (429 after the 5th request)
for i in $(seq 6); do curl -s -o /dev/null -w "%{http_code}\n" http://localhost:9003/; done

# Uploads
curl -X POST http://localhost:9000/upload/raw --data-binary @bigfile.bin
curl -X POST http://localhost:9000/upload/stream -F "file=@bigfile.bin"