Conversation
fix: add FlushAsync() to ensure data is sent immediately
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace SimpleFTP.Client | ||
| { | ||
| class _ | ||
| { | ||
| } | ||
| } |
| await using var writer = new StreamWriter(stream, Encoding.UTF8, leaveOpen: true); | ||
| await CommandHandler(stream, reader, writer); | ||
| } | ||
| catch (Exception excetpion) |
| /// <returns>Task representing the operation.</returns> | ||
| public static async Task StartClient() | ||
| { | ||
| using (TcpClient client = new TcpClient()) |
There was a problem hiding this comment.
| 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) |
There was a problem hiding this comment.
Методы по традиции именуются глаголами в повелительной форме, даже если это обработчики. "HandleCommand", например.
| private const string IP = "127.0.0.1"; | ||
| private const int PORT = 8888; |
There was a problem hiding this comment.
Это надо было бы передавать как параметры конструктора
| /// </summary> | ||
| public class Server | ||
| { | ||
| private const int Port = 8888; |
There was a problem hiding this comment.
Тоже, стоило бы принимать в конструктор
| /// <summary> | ||
| /// The main server class that manages listening for connections and client processing. | ||
| /// </summary> | ||
| public class Server |
There was a problem hiding this comment.
TcpListener IDisposable, поэтому и Server должен быть IDisposable, и вызывать у себя в Dispose его метод Dispose.
| try | ||
| { | ||
| TcpClient client = await this.listener.AcceptTcpClientAsync(this.cts.Token); | ||
| Task clientTask = Task.Run(() => this.ClientHandler(client)); |
There was a problem hiding this comment.
А дальше бы её дождаться при завершении работы сервера. Для этого таски стоит в список сложить.
| this.isWorking = false; | ||
| this.cts?.Cancel(); | ||
| this.listener?.Stop(); | ||
| } |
There was a problem hiding this comment.
И тут бы ещё дождаться (асинхронно), пока все клиенты не закончат свои дела.
| try | ||
| { | ||
| await using NetworkStream stream = client.GetStream(); | ||
| { |
No description provided.