Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:07:04+00:00 2026-06-18T08:07:04+00:00

Is sure that all data are read from a NetworkStream when DataAvailable is false?

  • 0

Is sure that all data are read from a NetworkStream when DataAvailable is false?

Or does the sender of the data have to send the length of the data first.
And I have to read until I have read the number of bytes specified by the sender?

Sampel:

private Byte[] ReadStream(NetworkStream ns)
{
    var bl = new List<Byte>();
    var receivedBytes = new Byte[128];
    while (ns.DataAvailable)
    {
            var bytesRead = ns.Read(receivedBytes, 0, receivedBytes.Length);
            if (bytesRead == receivedBytes.Length)
                bl.AddRange(receivedBytes);
            else
                bl.AddRange(receivedBytes.Take(bytesRead));
    }
    return bl.ToArray();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:07:05+00:00Added an answer on June 18, 2026 at 8:07 am

    DataAvailable just tells you what is buffered and available locally. It means exactly nothing in terms of what is likely to arrive. The most common use of DataAvailable is to decide between a sync read and an async read.

    If you are expecting the inbound stream to close after the send, then you can just keep using Read until a non-positive result is achieved, which tells you it has reached the end. If they are sending multiple frames, or just aren’t closing – then yes: you’ll need some way of detecting the end of a frame (=logical message). That can be via a length-prefix and counting, but it can also be via sentinel values. For example, in text-based protocols, \n or \r are often interpreted as “end of message”.

    So: it depends entirely on your protocol.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF service that uses ODP.NET to read data from an Oracle
Hi all i have written a code to read the excel data from an
I have been trying to test my application to make sure that all the
I have this annoying problem, that Im pretty sure happens to all of you
I have a UITableView that was created from data coming from a mutable array.
I have an application written in VB.NET that reads data from a file and
I have a text file that contains the following data. The first line is
I want to read all rows in a table using system.data.sqlite. As I have
I want to make sure that all 3 conditions result in the same answer
Is there away to make sure that all digits inside a INPUT#barcode start with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.