Skip to content

Added - #53

Open
IgnatSergeev wants to merge 1 commit into
mainfrom
kr1
Open

IgnatSergeev wants to merge 1 commit into
mainfrom
kr1

Conversation

@IgnatSergeev

Copy link
Copy Markdown
Owner

No description provided.

Comment on lines +16 to +18
ConsoleMutex.WaitOne();
Console.WriteLine(message);
ConsoleMutex.ReleaseMutex();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Консоль сама буквально это и делает :) AsyncConsole не нужен

Comment on lines +12 to +13
protected TcpClient Client = new ();
protected StreamWriter? Writer;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • protected-полями лучше вовсе не пользоваться, потомкам нельзя доверять.
  • Раз это не-public-поля, они именуются со строчной.
  • TcpClient реализует IDisposable, так что и весь класс должен реализовывать IDisposable, и в своём методе Dispose() вызывать Dispose у TcpClient

}

AsyncConsole.WriteLine("Disconnected");
Environment.Exit(0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не используйте Environment.Exit, это делает код непереиспользуемым, если надо выйти из чата, не убивая весь процесс, в котором он находится

Comment on lines +54 to +57
private static bool IsConnected(TcpClient client)
{
return GetState(client) == TcpState.Established;
}

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
private static bool IsConnected(TcpClient client)
{
return GetState(client) == TcpState.Established;
}
private static bool IsConnected(TcpClient client)
=> GetState(client) == TcpState.Established;

@@ -0,0 +1,12 @@
namespace ConsoleNetChat;

public class ChatterException : Exception

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Надо тоже комментарий

}
}

break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Компилятор выдаёт предупреждение, что выше while (true) с return, так что управление сюда никогда не попадёт

server.Disconnect();
return;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Архитектурно ужасно, что этот код в Main-е :)

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