From 233aa897a85a987826dfdb4405f6d5ff296731df Mon Sep 17 00:00:00 2001 From: Yegres546 <126583849+Yegres546@users.noreply.github.com> Date: Wed, 26 Nov 2025 00:52:24 +0200 Subject: [PATCH 1/3] Make 'HandleClientAsync' a static method. Program.cs --- EchoTcpServer/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EchoTcpServer/Program.cs b/EchoTcpServer/Program.cs index 5966c579..289bd60b 100644 --- a/EchoTcpServer/Program.cs +++ b/EchoTcpServer/Program.cs @@ -47,7 +47,7 @@ public async Task StartAsync() Console.WriteLine("Server shutdown."); } - private async Task HandleClientAsync(TcpClient client, CancellationToken token) + private static async Task HandleClientAsync(TcpClient client, CancellationToken cancellationToken) { using (NetworkStream stream = client.GetStream()) { @@ -170,4 +170,4 @@ public void Dispose() StopSending(); _udpClient.Dispose(); } -} \ No newline at end of file +} From 1bb56023910d41ae0af7b34249c9e9a25db3f7e1 Mon Sep 17 00:00:00 2001 From: Yegres546 <126583849+Yegres546@users.noreply.github.com> Date: Wed, 26 Nov 2025 01:03:01 +0200 Subject: [PATCH 2/3] Move 'UdpTimedSender' into a named namespace.Program.cs --- EchoTcpServer/Program.cs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/EchoTcpServer/Program.cs b/EchoTcpServer/Program.cs index 5966c579..7a6f595a 100644 --- a/EchoTcpServer/Program.cs +++ b/EchoTcpServer/Program.cs @@ -112,21 +112,22 @@ public static async Task Main(string[] args) } } - -public class UdpTimedSender : IDisposable +namespace EchoServerNamespace { - private readonly string _host; - private readonly int _port; - private readonly UdpClient _udpClient; - private Timer _timer; - - public UdpTimedSender(string host, int port) + public class UdpTimedSender : IDisposable { - _host = host; - _port = port; - _udpClient = new UdpClient(); - } + private readonly string _host; + private readonly int _port; + private readonly UdpClient _udpClient; + private Timer _timer; + public UdpTimedSender(string host, int port) + { + _host = host; + _port = port; + _udpClient = new UdpClient(); + } + } public void StartSending(int intervalMilliseconds) { if (_timer != null) @@ -170,4 +171,4 @@ public void Dispose() StopSending(); _udpClient.Dispose(); } -} \ No newline at end of file +} From 03733d6de32d5136145669fd5d992c11c318f0f1 Mon Sep 17 00:00:00 2001 From: Yegres546 <126583849+Yegres546@users.noreply.github.com> Date: Wed, 26 Nov 2025 01:06:18 +0200 Subject: [PATCH 3/3] Make 'HandleClientAsync' a static method.Program.cs --- EchoTcpServer/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EchoTcpServer/Program.cs b/EchoTcpServer/Program.cs index 7a6f595a..7f47378b 100644 --- a/EchoTcpServer/Program.cs +++ b/EchoTcpServer/Program.cs @@ -47,7 +47,7 @@ public async Task StartAsync() Console.WriteLine("Server shutdown."); } - private async Task HandleClientAsync(TcpClient client, CancellationToken token) + private static async Task HandleClientAsync(TcpClient client, CancellationToken token) { using (NetworkStream stream = client.GetStream()) {