Closed
Description
Type of issue
Other (describe below)
Description
In the Examples section, the following sentence refers to the use of the DataAvailable
property, however the shown code does not use the DataAvailable
property.
The following code example uses DataAvailable to determine if data is available to be read. If data is available, it reads from the NetworkStream.
byte[] myReadBuffer = new byte[1024];
StringBuilder myCompleteMessage = new StringBuilder();
int numberOfBytesRead = myNetworkStream.Read(myReadBuffer, 0, myReadBuffer.Length);
// Read all the data until the end of stream has been reached.
// The incoming message may be larger than the buffer size.
while (numberOfBytesRead > 0)
{
myCompleteMessage.Append(Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));
numberOfBytesRead = myNetworkStream.Read(myReadBuffer, 0, myReadBuffer.Length);
}
// Print out the received message to the console.
Console.WriteLine("You received the following message : " + myCompleteMessage);
Page URL
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Net.Sockets/NetworkStream.xml
Document Version Independent Id
b40c2ef4-b8a0-8de3-e71d-baf1aaae541b