In the following scenario;
System.Net.Sockets.TcpClient TC = SomeHowObtained;
System.Net.Sockets.NetworkStream NS = TC.GetStream();
Is there any difference between using NS.DataAvailable
and checking TC.Available > 0
?
In this case no, there is no difference. Internally NS.DataAvailable
returns true when Socket.Available != 0
. Since TC.Available
just return Socket.Available
and you are checking if that is greater than 0 you are basically doing the same thing.
From the MSDN:
NetworkStream.DataAvailable
Gets a value that indicates whether data is available on the NetworkStream to be read.
TcpClient.Available
Gets the amount of data that has been received from the network and is available to be read.
NetworkStream.DataAvailable
returns boolean
(true if data is available on the stream to be read), TcpClient.Available
returns Int32
(The number of bytes of data received from the network and available to be read)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With