Skip to content

Conversation

@Andrw-404
Copy link
Owner

No description provided.

Comment on lines +1 to +12
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleFTP.Client
{
class _
{
}
}

Choose a reason for hiding this comment

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

Хм

await using var writer = new StreamWriter(stream, Encoding.UTF8, leaveOpen: true);
await CommandHandler(stream, reader, writer);
}
catch (Exception excetpion)

Choose a reason for hiding this comment

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

Опечатка

/// <returns>Task representing the operation.</returns>
public static async Task StartClient()
{
using (TcpClient client = new TcpClient())

Choose a reason for hiding this comment

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

Suggested change
using (TcpClient client = new TcpClient())
using (TcpClient client = new())

Console.WriteLine("Disconnected from the server");
}

private static async Task CommandHandler(NetworkStream stream, StreamReader reader, StreamWriter writer)

Choose a reason for hiding this comment

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

Методы по традиции именуются глаголами в повелительной форме, даже если это обработчики. "HandleCommand", например.

Comment on lines +15 to +16
private const string IP = "127.0.0.1";
private const int PORT = 8888;

Choose a reason for hiding this comment

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

Это надо было бы передавать как параметры конструктора

/// </summary>
public class Server
{
private const int Port = 8888;

Choose a reason for hiding this comment

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

Тоже, стоило бы принимать в конструктор

/// <summary>
/// The main server class that manages listening for connections and client processing.
/// </summary>
public class Server

Choose a reason for hiding this comment

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

TcpListener IDisposable, поэтому и Server должен быть IDisposable, и вызывать у себя в Dispose его метод Dispose.

try
{
TcpClient client = await this.listener.AcceptTcpClientAsync(this.cts.Token);
Task clientTask = Task.Run(() => this.ClientHandler(client));

Choose a reason for hiding this comment

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

А дальше бы её дождаться при завершении работы сервера. Для этого таски стоит в список сложить.

this.isWorking = false;
this.cts?.Cancel();
this.listener?.Stop();
}

Choose a reason for hiding this comment

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

И тут бы ещё дождаться (асинхронно), пока все клиенты не закончат свои дела.

try
{
await using NetworkStream stream = client.GetStream();
{

Choose a reason for hiding this comment

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

Это вроде как не надо.

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