Added AesPassword

This commit is contained in:
Jeroen Saey
2025-08-21 07:45:14 +02:00
parent bdf2d1b935
commit 9564e2002d
6 changed files with 696 additions and 683 deletions

View File

@@ -1,27 +1,27 @@
using EonaCat.Connections;
using EonaCat.Connections.Models;
using System.Text;
namespace EonaCat.Connections.Client.Example
{
public class Program
{
private static NetworkClient _client;
public static async Task Main(string[] args)
{
await CreateClientAsync().ConfigureAwait(false);
while (true)
{
Console.Write("Enter message to send (or 'exit' to quit): ");
var message = Console.ReadLine();
if (!string.IsNullOrEmpty(message) && message.Equals("exit", StringComparison.OrdinalIgnoreCase))
{
await _client.DisconnectAsync().ConfigureAwait(false);
break;
}
using EonaCat.Connections;
using EonaCat.Connections.Models;
using System.Text;
namespace EonaCat.Connections.Client.Example
{
public class Program
{
private static NetworkClient _client;
public static async Task Main(string[] args)
{
await CreateClientAsync().ConfigureAwait(false);
while (true)
{
Console.Write("Enter message to send (or 'exit' to quit): ");
var message = Console.ReadLine();
if (!string.IsNullOrEmpty(message) && message.Equals("exit", StringComparison.OrdinalIgnoreCase))
{
await _client.DisconnectAsync().ConfigureAwait(false);
break;
}
var jsonUrl = "https://microsoftedge.github.io/Demos/json-dummy-data/5MB-min.json";
try
@@ -35,46 +35,47 @@ namespace EonaCat.Connections.Client.Example
catch (Exception ex)
{
Console.WriteLine($"Failed to download large JSON file: {ex.Message}");
}
if (!string.IsNullOrEmpty(message))
{
await _client.SendAsync(message).ConfigureAwait(false);
}
}
}
private static async Task CreateClientAsync()
{
var config = new Configuration
{
Protocol = ProtocolType.TCP,
Host = "127.0.0.1",
Port = 1111,
UseSsl = false,
UseAesEncryption = false,
//ServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2("client.pfx", "p@ss"),
};
_client = new NetworkClient(config);
// Subscribe to events
_client.OnConnected += (sender, e) =>
Console.WriteLine($"Connected to server at {e.RemoteEndPoint}");
_client.OnDataReceived += (sender, e) =>
Console.WriteLine($"Server says: {(e.IsBinary ? $"{e.Data.Length} bytes" : e.StringData)}");
_client.OnDisconnected += (sender, e) =>
Console.WriteLine("Disconnected from server");
await _client.ConnectAsync();
// Send nickname
await _client.SendNicknameAsync("TestUser");
// Send a message
await _client.SendAsync("Hello server!");
}
}
}
if (!string.IsNullOrEmpty(message))
{
await _client.SendAsync(message).ConfigureAwait(false);
}
}
}
private static async Task CreateClientAsync()
{
var config = new Configuration
{
Protocol = ProtocolType.TCP,
Host = "127.0.0.1",
Port = 1111,
UseSsl = false,
UseAesEncryption = true,
AesPassword = "p@ss",
//ServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2("client.pfx", "p@ss"),
};
_client = new NetworkClient(config);
// Subscribe to events
_client.OnConnected += (sender, e) =>
Console.WriteLine($"Connected to server at {e.RemoteEndPoint}");
_client.OnDataReceived += (sender, e) =>
Console.WriteLine($"Server says: {(e.IsBinary ? $"{e.Data.Length} bytes" : e.StringData)}");
_client.OnDisconnected += (sender, e) =>
Console.WriteLine("Disconnected from server");
await _client.ConnectAsync();
// Send nickname
await _client.SendNicknameAsync("TestUser");
// Send a message
await _client.SendAsync("Hello server!");
}
}
}