Skip to content

Comments

thirdTest#8

Open
Andrw-404 wants to merge 1 commit intomainfrom
thirdtest
Open

thirdTest#8
Andrw-404 wants to merge 1 commit intomainfrom
thirdtest

Conversation

@Andrw-404
Copy link
Owner

No description provided.

using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Подозреваю, что тут много ненужных using-ов, и их лучше внутри namespace писать

using System.Text;
using System.Threading.Tasks;

namespace thirdTestTask;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пространства имён в .NET именуются с заглавной всегда


namespace thirdTestTask;

public static class App

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Комментариев не хватает

<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StyleCop бы ещё

private static bool TryParseServer(string[] args, out int port)
{
port = 0;
return args.Length == 1 && int.TryParse(args[0], out port);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Стоило бы заодно проверить, принадлежит ли номер порта разрешённому диапазону.

public static async Task RunAsync(TcpClient client, TextReader input, TextWriter output, CancellationToken token = default)
{
using var cts = CancellationTokenSource.CreateLinkedTokenSource(token);
CancellationToken token2 = cts.Token;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что-то сложно. Можно было дальше cts.Token и использовать

using var cts = CancellationTokenSource.CreateLinkedTokenSource(token);
CancellationToken token2 = cts.Token;

NetworkStream stream = client.GetStream();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using? Клиент сам его закроет, но вообще NetworkStream IDisposable, поэтому можно дать ему самому разобраться, когда надо закрыться

{
while (!token2.IsCancellationRequested)
{
string? msg = await reader.ReadLineAsync();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сюда бы тоже CancellationToken, чтобы мы не ждали вечно сообщения

{
output.WriteLine(text);
output.Flush();
return Task.CompletedTask;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну такое это async. Выглядит как обман почтенной публики, операция выполняется синхронно


try
{
Console.WriteLine($"[Сервер] Ожидание подлюкчения на порту {port}...");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Console.WriteLine($"[Сервер] Ожидание подлюкчения на порту {port}...");
Console.WriteLine($"[Сервер] Ожидание подключения на порту {port}...");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants