Skip to content

3 semestr kr1#24

Open
Palezehvat wants to merge 3 commits intomasterfrom
3SemestrKr1
Open

3 semestr kr1#24
Palezehvat wants to merge 3 commits intomasterfrom
3SemestrKr1

Conversation

@Palezehvat
Copy link
Owner

No description provided.

Copy link

@yurii-litvinov yurii-litvinov left a comment

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)

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)
{

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

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

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

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

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

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)

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

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;

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

Comments