Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetworkStream.DataAvailable vs. TcpClient.Available

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?

like image 523
paul simmons Avatar asked Dec 15 '12 11:12

paul simmons


2 Answers

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.

like image 84
Rutix Avatar answered Oct 20 '22 06:10

Rutix


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)

like image 40
Soner Gönül Avatar answered Oct 20 '22 08:10

Soner Gönül