No description
Find a file
2025-03-06 00:19:46 -05:00
.github/workflows Link OpenSSL in CI build 2025-03-02 17:02:51 -05:00
src Fix encrypt/decrypt string bug, since Nim strings both have a length field and a null terminator 2025-03-06 00:12:56 -05:00
tests Fix encrypt/decrypt string bug, since Nim strings both have a length field and a null terminator 2025-03-06 00:12:56 -05:00
.gitignore Test client and server implementations 2025-02-25 20:49:52 -05:00
config.nims OpenSSL headers no longer required 2025-03-02 16:53:53 -05:00
LICENSE Init 2025-02-17 21:59:06 -05:00
Makefile Fix libcrypto dynamic linking 2025-03-02 17:09:50 -05:00
nimdtp.nimble Init 2025-02-17 21:59:06 -05:00
README.md Add missing example comments 2025-03-05 23:44:16 -05:00

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.