Initial version
This commit is contained in:
159
README.md
159
README.md
@@ -1,3 +1,158 @@
|
||||
# EonaCat.FastNetwork
|
||||
# 🔥 EonaCat.FastNetwork 🔥
|
||||
|
||||
A **lightweight, asynchronous, and secure networking framework** for C# that provides TCP and UDP client-server communication with built-in **AES encryption**, **SSL/TLS support**, **auto-reconnection**, and **heartbeat monitoring**.
|
||||
|
||||
This project contains:
|
||||
- `FastNetworkClient` — A configurable client capable of connecting to servers over TCP or UDP.
|
||||
- `FastNetworkServer` — A high-performance server capable of managing multiple clients, broadcasting messages, and monitoring connections.
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Features
|
||||
|
||||
✅ Supports both **TCP** and **UDP** communication
|
||||
✅ **Asynchronous I/O** with `async/await`
|
||||
✅ Optional **AES encryption** for secure communication
|
||||
✅ Optional **SSL/TLS** (via `SslStream`)
|
||||
✅ **Automatic reconnection** logic for clients
|
||||
✅ **Heartbeat system** for connection health checks
|
||||
✅ **Client nickname management**
|
||||
✅ **Server broadcasting and targeted messaging**
|
||||
✅ **Configurable limits** (buffer size, timeouts, max connections, etc.)
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ Configuration
|
||||
|
||||
Both the client and server use a `FastNetworkConfig` object to control behavior.
|
||||
|
||||
### Example Configuration
|
||||
```csharp
|
||||
var config = new FastNetworkConfig
|
||||
{
|
||||
Protocol = ProtocolType.TCP,
|
||||
UseAES = true,
|
||||
AESKey = "your-256-bit-key",
|
||||
UseSSL = false,
|
||||
AutoReconnect = true,
|
||||
HeartbeatIntervalMs = 5000,
|
||||
ReconnectDelayMs = 3000,
|
||||
MaxReconnectAttempts = 5,
|
||||
TimeoutMs = 10000,
|
||||
BufferSize = 4096
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
💻 Usage:
|
||||
|
||||
🤩 Server Example
|
||||
|
||||
```csharp
|
||||
using EonaCat.FastNetwork;
|
||||
using EonaCat.FastNetwork.Models;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main()
|
||||
{
|
||||
var config = new FastNetworkConfig
|
||||
{
|
||||
Protocol = ProtocolType.TCP,
|
||||
UseAES = true,
|
||||
AESKey = "your-256-bit-key",
|
||||
AutoReconnect = true
|
||||
};
|
||||
|
||||
var server = new FastNetworkServer(config);
|
||||
|
||||
server.ClientConnected += (s, info) =>
|
||||
{
|
||||
Console.WriteLine($"Client connected: {info.Id} ({info.RemoteEndPoint})");
|
||||
};
|
||||
|
||||
server.MessageReceived += async (s, msg) =>
|
||||
{
|
||||
Console.WriteLine($"Message from {msg.SenderId}: {Encoding.UTF8.GetString(msg.Data)}");
|
||||
await server.SendToClientAsync(msg.SenderId, Encoding.UTF8.GetBytes("Message received!"));
|
||||
};
|
||||
|
||||
server.ClientDisconnected += (s, info) =>
|
||||
{
|
||||
Console.WriteLine($"Client disconnected: {info.Id}");
|
||||
};
|
||||
|
||||
await server.StartAsync(5000);
|
||||
Console.WriteLine("Server running on port 5000...");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
😋 Client Example
|
||||
```csharp
|
||||
using EonaCat.FastNetwork;
|
||||
using EonaCat.FastNetwork.Models;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
class Program
|
||||
{
|
||||
static async Task Main()
|
||||
{
|
||||
var config = new FastNetworkConfig
|
||||
{
|
||||
Protocol = ProtocolType.TCP,
|
||||
UseAES = true,
|
||||
AESKey = "your-256-bit-key",
|
||||
AutoReconnect = true
|
||||
};
|
||||
|
||||
var client = new FastNetworkClient(config);
|
||||
|
||||
client.StateChanged += (s, state) =>
|
||||
{
|
||||
Console.WriteLine($"Client state: {state}");
|
||||
};
|
||||
|
||||
client.MessageReceived += (s, data) =>
|
||||
{
|
||||
Console.WriteLine($"Received: {Encoding.UTF8.GetString(data)}");
|
||||
};
|
||||
|
||||
await client.ConnectAsync("127.0.0.1", 5000);
|
||||
Console.WriteLine("Connected to server.");
|
||||
|
||||
await client.SendAsync(Encoding.UTF8.GetBytes("Hello Server!"));
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
🔒 Security Options
|
||||
|
||||
🐦🔥AES Encryption
|
||||
|
||||
Enable AES encryption by setting:
|
||||
|
||||
```csharp
|
||||
config.UseAES = true;
|
||||
config.AESKey = "your-256-bit-secret-key";
|
||||
```
|
||||
|
||||
🦅SSL/TLS
|
||||
|
||||
Enable SSL by providing a certificate:
|
||||
```csharp
|
||||
config.UseSSL = true;
|
||||
config.Certificates = new[] { yourX509Certificate };
|
||||
```
|
||||
|
||||
🔁 Auto-Reconnect & Heartbeat
|
||||
|
||||
The client will automatically attempt to reconnect if the connection fails, if AutoReconnect = true.
|
||||
|
||||
The server uses heartbeats and timeouts to monitor inactive clients and disconnect them.
|
||||
|
||||
EonaCat.FastNetwork
|
||||
Reference in New Issue
Block a user