https://github.com/wkhallen/csdtp
Modern networking interfaces for C#.
https://github.com/wkhallen/csdtp
csharp networking socket socket-client socket-server
Last synced: 3 months ago
JSON representation
Modern networking interfaces for C#.
- Host: GitHub
- URL: https://github.com/wkhallen/csdtp
- Owner: WKHAllen
- License: mit
- Created: 2022-04-24T20:24:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-22T01:19:38.000Z (almost 3 years ago)
- Last Synced: 2025-01-27T11:22:46.261Z (11 months ago)
- Topics: csharp, networking, socket, socket-client, socket-server
- Language: C#
- Homepage: https://wkhallen.com/dtp
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Data Transfer Protocol for C#
Modern networking interfaces for C#.
## 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](https://wkhallen.com/dtp/).
## Installation
Install the package:
```sh
$ nuget install CSDTP
```
## Creating a server
A server can be built using the `Server` implementation:
```csharp
using CSDTP;
// Create a server that receives strings and returns the length of each string
public class MyServer : Server
{
protected override void Receive(ulong clientId, string data)
{
// Send back the length of the string
Send(clientId, data.Length);
}
protected override void Connect(ulong clientId)
{
Console.WriteLine("Client with ID {0} connected", clientId);
}
protected override void Disconnect(ulong clientId)
{
Console.WriteLine("Client with ID {0} disconnected", clientId);
}
}
public class Main
{
public static void Main()
{
// Start the server
var server = new MyServer();
server.Start("127.0.0.1", 29275);
}
}
```
## Creating a client
A client can be built using the `Client` implementation:
```csharp
using CSDTP;
// Create a client that sends a message to the server and receives the length of the message
public class MyClient : Client
{
private readonly string _message;
public MyClient(string message)
{
_message = message;
}
protected override void Receive(int data)
{
// Validate the response
Console.WriteLine("Received response from server: {0}", data);
Assert.AreEqual(data, _message.Length);
}
protected override void Disconnected()
{
Console.WriteLine("Unexpectedly disconnected from server");
}
}
public class Main
{
public static void Main()
{
// Connect to the server
var message = "Hello, server!";
var client = new MyClient(message);
client.Connect("127.0.0.1", 29275);
// Send a message to the server
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.