Skip to content

Server#4

Open
MinyazevR wants to merge 5 commits intomainfrom
Server
Open

Server#4
MinyazevR wants to merge 5 commits intomainfrom
Server

Conversation

@MinyazevR
Copy link
Copy Markdown
Owner

No description provided.

Comment on lines +33 to +36
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);
Copy link
Copy Markdown

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>
Copy link
Copy Markdown

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();


Copy link
Copy Markdown

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}");
Copy link
Copy Markdown

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);
Copy link
Copy Markdown

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])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
switch(args[i])
switch (args[i])

{
case "list":
{
var (size, names) = await Task.Run(() => client.List(args[i + 1]));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
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;
Copy link
Copy Markdown

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();
Copy link
Copy Markdown

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]);
Copy link
Copy Markdown

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