private async void RecieveAsync(Socket client, ChannelWriter <byte> writer) { try { var buffer = new byte[client.ReceiveBufferSize]; while (!cancellationTokenSource.IsCancellationRequested) { var bytesRead = await client.ReceiveAsync(buffer, SocketFlags.None); if (bytesRead == 0) { client.Dispose(); return; } await writer.WriteArrayAsync(buffer, bytesRead); } } catch (Exception ex) { logger.Error("Error during recieving data from socket", ex); } }