Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"DataAvailable" property referred to but not used in code example #10896

Open
robertpba opened this issue Jan 31, 2025 · 3 comments · May be fixed by #10898
Open

"DataAvailable" property referred to but not used in code example #10896

robertpba opened this issue Jan 31, 2025 · 3 comments · May be fixed by #10898
Labels
area-System.Net.Sockets help wanted Good for community contributors to help [up-for-grabs] untriaged New issue has not been triaged by the area owner

Comments

@robertpba
Copy link

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

https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.networkstream.read?view=net-9.0#system-net-sockets-networkstream-read(system-byte()-system-int32-system-int32)

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

Article author

@karelz

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 31, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl

@antonfirsov
Copy link
Member

antonfirsov commented Jan 31, 2025

Good catch, thanks! This is an overlook from #8537 which changed the code sample to read until EOF instead of checking DataAvailable, but I forgot to change the text.

Previously, the example used DataAvailable instead of EOF to detect end of transmission, which is wrong.

@antonfirsov antonfirsov added the help wanted Good for community contributors to help [up-for-grabs] label Jan 31, 2025
@antonfirsov
Copy link
Member

Fixing this should be trivial, if anyone is interested, go ahead!

@flafarga flafarga linked a pull request Feb 1, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Net.Sockets help wanted Good for community contributors to help [up-for-grabs] untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants