Skip to content

3 semestr kr1 - #24

Open
Palezehvat wants to merge 3 commits into
masterfrom
3SemestrKr1
Open

Palezehvat wants to merge 3 commits into
masterfrom
3SemestrKr1

Conversation

@Palezehvat

Copy link
Copy Markdown
Owner

No description provided.

@yurii-litvinov yurii-litvinov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не работает — не вызываете Start для _listener, Talk думает, что он всегда сервер. И тестов нет.

Comment on lines +4 to +6
class Program
{
public static async Task Main(string[] args)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это в современном .NET можно не писать. Компилятор сам поймёт по телу программы, что Main надо сгенерировать асинхронным

{
public static async Task Main(string[] args)
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

После { пустая строка не ставится


if (args == null || args.Length > 2 || args.Length == 0)
{
throw new ArgumentException();

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 — это место, где ловят исключения, а не кидают (тут надо вывести дружественное к пользователю сообщение об ошибке, а не стек вызовов из одного фрейма и без пояснений, какой именно аргумент не понравился). Не пишите throw в Main.

Comment on lines +14 to +15
var port = 0;
var correct = int.TryParse(args[0], out 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.

Suggested change
var port = 0;
var correct = int.TryParse(args[0], out port);
var correct = int.TryParse(args[0], out int port);

}
if (args.Length == 1)
{
var server = new ServerAndClient(8888);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Значение аргумента в этом случае игнорируется и сервер всё равно запускается на порту 8888?

{
_port = port;
_ipAddress = ipAdress;
_client = new TcpClient(ipAdress, 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.

А я бы не смешивал понятия сервера и клиента. Потому что у одного есть TcpClient, у другого TcpListener, и они никогда не могут быть не null вместе.

{
if (_socket == null || stream == null)
{
throw new ArgumentNullException();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Но Talk() не принимает аргументов :) Тут правильнее InvalidOperationExpression

var writer = new StreamWriter(stream);
var reader = new StreamReader(stream);
var data = reader.ReadToEnd();
if (string.Compare(data, "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.

Хм, в таком виде это то же самое, что и data == "exit"

_socket.Shutdown(SocketShutdown.Both);
if (_client != null)
{
_client.Close();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это был бы надёжный способ закрыть соединение, не реализуя никакой IDisposable, если бы не было исключений.

@@ -0,0 +1,70 @@
using System.Net;
using System.Net.Sockets;
using System.Net.WebSockets;

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.

3 participants