-
Notifications
You must be signed in to change notification settings - Fork 0
Server #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
Added tests and comments
Changed tests Added comments
| var server = new Server.Server(ip!, port); | ||
| var cancelTokenSource = new CancellationTokenSource(); | ||
| var serverTask = Task.Run(() => server.Start(cancelTokenSource), cancelTokenSource.Token); | ||
| var client = new Server.Client(ip!, port); |
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> | ||
| /// <param name="stream">stream</param> | ||
| /// <param name="path">path to directory</param> | ||
| /// <returns></returns> |
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 var 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.
Две пустые строки подряд — тоже :)
| using var streamWriter = new StreamWriter(stream) { AutoFlush = true }; | ||
|
|
||
| // Отправляем сообщение подключенному tcpсерверу. | ||
| await streamWriter.WriteLineAsync($"list {pathToDiretory}"); |
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.
Нарушение протокола, list в условии кодируется единицей
| i++; | ||
| } | ||
|
|
||
| return (size, list); |
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.
Список сам знает свой размер, так что size несколько избыточен
|
|
||
| for (int i = 2; i < args.Length; i++) | ||
| { | ||
| switch(args[i]) |
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.
| switch(args[i]) | |
| switch (args[i]) |
| { | ||
| case "list": | ||
| { | ||
| var (size, names) = await Task.Run(() => client.List(args[i + 1])); |
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.
| var (size, names) = await Task.Run(() => client.List(args[i + 1])); | |
| var (size, names) = await client.List(args[i + 1]); |
async-методы и так Task всегда возвращают, уже исполняющийся. Оборачивать их с помощью Task.Run нет смысла. Тут и много где ещё.
|
|
||
| public class Tests | ||
| { | ||
| Server? 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.
private
| } | ||
|
|
||
| var server = new Server.Server(ip!, port); | ||
| var cancelTokenSource = new CancellationTokenSource(); |
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.
По-хорошему, сервер надо остановить в конце и дождаться остановки
| Console.WriteLine($"size : {size}"); | ||
| for (int j = 0; j < bytes.Length; j++) | ||
| { | ||
| Console.Write(bytes[j]); |
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.