-
Notifications
You must be signed in to change notification settings - Fork 0
SimpleFTP #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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 _ | ||
| { | ||
| } | ||
| } |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Методы по традиции именуются глаголами в повелительной форме, даже если это обработчики. "HandleCommand", например.
| private const string IP = "127.0.0.1"; | ||
| private const int PORT = 8888; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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(); | ||
| } |
There was a problem hiding this comment.
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(); | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это вроде как не надо.
No description provided.