Conversation
| using System.Linq; | ||
| using System.Net; | ||
| using System.Text; | ||
| using System.Threading.Tasks; |
There was a problem hiding this comment.
Подозреваю, что тут много ненужных using-ов, и их лучше внутри namespace писать
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace thirdTestTask; |
There was a problem hiding this comment.
Пространства имён в .NET именуются с заглавной всегда
|
|
||
| namespace thirdTestTask; | ||
|
|
||
| public static class App |
| <TargetFramework>net9.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> |
| private static bool TryParseServer(string[] args, out int port) | ||
| { | ||
| port = 0; | ||
| return args.Length == 1 && int.TryParse(args[0], out port); |
There was a problem hiding this comment.
Стоило бы заодно проверить, принадлежит ли номер порта разрешённому диапазону.
| public static async Task RunAsync(TcpClient client, TextReader input, TextWriter output, CancellationToken token = default) | ||
| { | ||
| using var cts = CancellationTokenSource.CreateLinkedTokenSource(token); | ||
| CancellationToken token2 = cts.Token; |
There was a problem hiding this comment.
Что-то сложно. Можно было дальше cts.Token и использовать
| using var cts = CancellationTokenSource.CreateLinkedTokenSource(token); | ||
| CancellationToken token2 = cts.Token; | ||
|
|
||
| NetworkStream stream = client.GetStream(); |
There was a problem hiding this comment.
using? Клиент сам его закроет, но вообще NetworkStream IDisposable, поэтому можно дать ему самому разобраться, когда надо закрыться
| { | ||
| while (!token2.IsCancellationRequested) | ||
| { | ||
| string? msg = await reader.ReadLineAsync(); |
There was a problem hiding this comment.
Сюда бы тоже CancellationToken, чтобы мы не ждали вечно сообщения
| { | ||
| output.WriteLine(text); | ||
| output.Flush(); | ||
| return Task.CompletedTask; |
There was a problem hiding this comment.
Ну такое это async. Выглядит как обман почтенной публики, операция выполняется синхронно
|
|
||
| try | ||
| { | ||
| Console.WriteLine($"[Сервер] Ожидание подлюкчения на порту {port}..."); |
There was a problem hiding this comment.
| Console.WriteLine($"[Сервер] Ожидание подлюкчения на порту {port}..."); | |
| Console.WriteLine($"[Сервер] Ожидание подключения на порту {port}..."); |
No description provided.