From 1a154166132cb7161d6c896c60539984ce327670 Mon Sep 17 00:00:00 2001 From: EonaCat Date: Wed, 20 Aug 2025 20:28:47 +0200 Subject: [PATCH] Added client title counter in example --- EonaCat.Connections.Client/Program.cs | 9 ++++++--- EonaCat.Connections.Server/Program.cs | 10 +++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/EonaCat.Connections.Client/Program.cs b/EonaCat.Connections.Client/Program.cs index fc68cff..1fbd48a 100644 --- a/EonaCat.Connections.Client/Program.cs +++ b/EonaCat.Connections.Client/Program.cs @@ -9,7 +9,10 @@ namespace EonaCat.Connections.Client.Example public static void Main(string[] args) { - CreateClientAsync().ConfigureAwait(false); + for (int i = 0; i < 100000; i++) + { + CreateClientAsync(i).ConfigureAwait(false); + } while (true) { @@ -28,7 +31,7 @@ namespace EonaCat.Connections.Client.Example } } - private static async Task CreateClientAsync() + private static async Task CreateClientAsync(int i) { var config = new Configuration { @@ -55,7 +58,7 @@ namespace EonaCat.Connections.Client.Example await _client.ConnectAsync(); // Send nickname - await _client.SendNicknameAsync("TestUser"); + await _client.SendNicknameAsync($"TestUser{i}"); // Send a message await _client.SendAsync("Hello server!"); diff --git a/EonaCat.Connections.Server/Program.cs b/EonaCat.Connections.Server/Program.cs index 4e5eae2..f41ec5f 100644 --- a/EonaCat.Connections.Server/Program.cs +++ b/EonaCat.Connections.Server/Program.cs @@ -43,13 +43,18 @@ namespace EonaCat.Connections.Server.Example }; _server = new NetworkServer(config); - + int totalClients = 0; // Subscribe to events _server.OnConnected += (sender, e) => + { Console.WriteLine($"Client {e.ClientId} connected from {e.RemoteEndPoint}"); + Console.Title = $"Active Connections: {++totalClients}"; + }; _server.OnConnectedWithNickname += (sender, e) => + { Console.WriteLine($"Client {e.ClientId} connected with nickname: {e.Nickname}"); + }; _server.OnDataReceived += async (sender, e) => { @@ -67,7 +72,10 @@ namespace EonaCat.Connections.Server.Example }; _server.OnDisconnected += (sender, e) => + { Console.WriteLine($"Client {e.ClientId} disconnected"); + Console.Title = $"Active Connections: {--totalClients}"; + }; await _server.StartAsync(); }