-
Notifications
You must be signed in to change notification settings - Fork 0
Test 2 #7
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
|
|
||
| private readonly CancellationTokenSource source = new(); | ||
|
|
||
| public CancellationTokenSource GetSource => source; |
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.
Свойства обычно не именуют с Get
| this.address = adress; | ||
| } | ||
|
|
||
| // Принять сообщение |
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-функции XML Documentation тоже вполне можно писать. Обычные комментарии используются для комментирования внутри тел методов в основном.
| // Принять сообщение | ||
| private async Task GetMessage(NetworkStream stream) { | ||
| using var streamReader = new StreamReader(stream); | ||
| var data = (await streamReader.ReadLineAsync()); |
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 data = (await streamReader.ReadLineAsync()); | |
| var data = await streamReader.ReadLineAsync(); |
| // Отправить сообщение | ||
| private async Task SendMessage(NetworkStream stream) | ||
| { | ||
| using var streamWriter = new StreamWriter(stream) { AutoFlush = true}; |
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}; | |
| using var streamWriter = new StreamWriter(stream) { AutoFlush = true }; |
| { | ||
| break; | ||
| } | ||
| } |
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 readonly CancellationTokenSource source = new(); | ||
|
|
||
| public CancellationTokenSource GetSource => source ; |
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.
| public CancellationTokenSource GetSource => source ; | |
| public CancellationTokenSource GetSource => source; |
| // Блокируем поток до установления соединения | ||
| var acceptedSocket = await tcpListener.AcceptSocketAsync(); | ||
| // Поток для записи и чтения в полученный сокет | ||
| using var newtworkStream = new NetworkStream(acceptedSocket); |
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.
networkStream
| Task a = Task.Run(() => SendMessage(newtworkStream)); | ||
| Task b = Task.Run(() => GetMessage(newtworkStream)); |
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.
Их бы запоминать и подождать в конце метода
|
|
||
| public class Tests2Tests | ||
| { | ||
| 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
| [Test] | ||
| public void Test1() | ||
| { | ||
|
|
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.