nimdtp

Modern networking interfaces for Nim.

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.1.0
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:26

Authors

  • WKHAllen

Installation

nimble install nimdtp
choosenim install nimdtp
git clone https://github.com/WKHAllen/nimdtp

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
nimdtp - - - - - - -

Dependencies

Package Version Optional
nim >= 2.0.0 No

Source

Repository https://github.com/WKHAllen/nimdtp
Homepage https://github.com/WKHAllen/nimdtp
Registry Source nimble_official

README

Data Transfer Protocol for Nim

Modern networking interfaces for Nim.

Data Transfer Protocol

The Data Transfer Protocol (DTP) is a larger project to make ergonomic network programming available in any language. See the full project here.

Installation

Install the package:

$ nimble install nimdtp

Add the package in <project>.nimble:

requires "nimdtp == 0.1.0"

Creating a server

A server can be built using the Server implementation:

import nimdtp/server

# Called when data is received from a client
proc receive(server: Server[int, string], clientId: int, data: string) =
  # Send back the length of the string
  asyncCheck server.send(clientId, data.len)

# Called when a client connects
proc connect(server: Server[int, string], clientId: int) =
  echo "Client with ID ", clientId, " connected"

# Called when a client disconnects
proc disconnect(server: Server[int, string], clientId: int) =
  echo "Client with ID ", clientId, " disconnected"

# Create a server that receives strings and returns the length of each string
let server = newServer[int, string](onReceive=receive, onConnect=connect, onDisconnect=disconnect)
waitFor server.start("127.0.0.1", 29275)

Creating a client

A client can be built using the Client implementation:

import nimdtp/client

let message = "Hello, server!"

# Called when data is received from the server
proc receive(client: Client[string, int], data: int) =
  # Validate the response
  echo "Received response from server: ", data
  assert data == message.len

# Called when the client is disconnected from the server
proc disconnected(client: Client[string, int]) =
  echo "Unexpected disconnected from server"

# Create a client that sends a message to the server and receives the length of the message
let client = newClient(onReceive=receive, onDisconnected=disconnected)
waitFor client.connect("127.0.0.1", 29275)
# Send the message to the server
waitFor client.send(message)

Security

Information security comes included. Every message sent over a network interface is encrypted with AES-256. Key exchanges are performed using a 2048-bit RSA key-pair.