Added Proxy Tester

This commit is contained in:
2025-10-01 21:26:56 +02:00
parent f79198e5aa
commit cbfab2ee63
8 changed files with 364 additions and 45 deletions

View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36414.22 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxyTester.Client", "ProxyTester.Client\ProxyTester.Client.csproj", "{ED4C1612-ABFE-491B-AF0C-90F2647C1F51}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxyTester.Server", "..\ProxyTester.Server\ProxyTester.Server\ProxyTester.Server.csproj", "{DE7E42AB-EC8A-472D-B379-6E1DB1E1E96C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ED4C1612-ABFE-491B-AF0C-90F2647C1F51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED4C1612-ABFE-491B-AF0C-90F2647C1F51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED4C1612-ABFE-491B-AF0C-90F2647C1F51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED4C1612-ABFE-491B-AF0C-90F2647C1F51}.Release|Any CPU.Build.0 = Release|Any CPU
{DE7E42AB-EC8A-472D-B379-6E1DB1E1E96C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE7E42AB-EC8A-472D-B379-6E1DB1E1E96C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE7E42AB-EC8A-472D-B379-6E1DB1E1E96C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE7E42AB-EC8A-472D-B379-6E1DB1E1E96C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {27ABD586-54C9-4ECB-B2B0-BF0C21B80D31}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,86 @@
using EonaCat.Connections.Models;
using System.Net.Sockets;
namespace EonaCat.Connections.Client.Example
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
public class Program
{
private static NetworkClient _client;
public static async Task Main(string[] args)
{
for (int i = 0; i < 100; i++)
{
await CreateClientAsync().ConfigureAwait(false);
}
while (true)
{
if (!_client.IsConnected)
{
await Task.Delay(1000).ConfigureAwait(false);
continue;
}
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;
}
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 = 2222,
UseSsl = true,
UseAesEncryption = true,
AesPassword = "EonaCat.Connections.Password",
Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2("certificate.pfx", "p@ss"),
};
_client = new NetworkClient(config);
_client.OnGeneralError += (sender, e) =>
Console.WriteLine($"Error: {e.Message}");
// Subscribe to events
_client.OnConnected += async (sender, e) =>
{
Console.WriteLine($"Connected to server at {e.RemoteEndPoint}");
// Set nickname
await _client.SendNicknameAsync("TestUser");
// Send a message
await _client.SendAsync("Hello server!");
};
_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");
};
Console.WriteLine("Connecting to server...");
await _client.ConnectAsync();
}
}
}

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EonaCat.Connections" Version="1.0.8" />
</ItemGroup>
<ItemGroup>
<None Update="certificate.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,95 @@
using EonaCat.Connections.Models;
using System.Net.Sockets;
namespace EonaCat.Connections.Server.Example
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
public class Program
{
private static NetworkServer _server;
public static void Main(string[] args)
{
CreateServerAsync().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))
{
_server.Stop();
_server.Dispose();
Console.WriteLine("Server stopped.");
break;
}
if (!string.IsNullOrEmpty(message))
{
_server.BroadcastAsync(message).ConfigureAwait(false);
}
}
}
private static async Task CreateServerAsync()
{
var config = new Configuration
{
Protocol = ProtocolType.TCP,
Port = 1111,
UseSsl = true,
UseAesEncryption = true,
MaxConnections = 100000,
AesPassword = "EonaCat.Connections.Password",
Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2("certificate.pfx", "p@ss")
};
_server = new NetworkServer(config);
// Subscribe to events
_server.OnConnected += (sender, e) =>
Console.WriteLine($"Client {e.ClientId} connected from {e.RemoteEndPoint}");
_server.OnConnectedWithNickname += (sender, e) =>
Console.WriteLine($"Client {e.ClientId} connected with nickname: {e.Nickname}");
_server.OnDataReceived += async (sender, e) =>
{
if (e.HasNickname)
{
Console.WriteLine($"Received from {e.Nickname}: {(e.IsBinary ? $"{e.Data.Length} bytes" : e.StringData)}");
}
else
{
Console.WriteLine($"Received from {e.ClientId}: {(e.IsBinary ? $"{e.Data.Length} bytes" : e.StringData)}");
}
// Echo back the message
if (e.IsBinary)
{
await _server.SendToClientAsync(e.ClientId, e.Data);
}
else
{
await _server.SendToClientAsync(e.ClientId, $"Echo: {e.StringData}");
}
};
_server.OnDisconnected += (sender, e) =>
{
if (e.HasNickname)
{
Console.WriteLine($"Client {e.Nickname} disconnected");
}
else
{
Console.WriteLine($"Client {e.ClientId} disconnected");
}
};
await _server.StartAsync();
}
}
}

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EonaCat.Connections" Version="1.0.8" />
</ItemGroup>
<ItemGroup>
<None Update="certificate.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>