作者: luckiejacky 時間: 2018-1-2 14:15 標題: 點解server 做緊streaming, NetworkStream.read is blocking?
C#, tcp client..
- NetworkStream stream = client.GetStream();
- byte[] buffer = new byte[640 * 480];
- int read, total = 0;
-
- // Blocking Read here
- while ((read = stream.Read(buffer, total, 1000)) != 0)
- {
- total += read;
- }
作者: Charcoal99 時間: 2018-1-2 18:38
https://msdn.microsoft.com/en-us ... .networkstream.aspx
NetworkStream class 提供的Methods 有 Read 及 ReadAsync 兩種,
當中的Read是synchronous的, 所以 comment 是blocking read.
作者: luckiejacky 時間: 2018-1-2 18:56
Thanks ching
作者: jasonchan35 時間: 2018-1-2 23:53
can check NetworkStream.DataAvailable before read
which can avoid blocking
