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

  • Home
  • SEARCH
  • 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 4110138
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:53:42+00:00 2026-05-20T21:53:42+00:00

I got a server that is managing two clients through NetworkStream.Read . Application protocol

  • 0

I got a server that is managing two clients through NetworkStream.Read.

Application protocol is:

ClientMessage [128 Bytes] → Response from Server [128 Bytes]

Now at server-side: Is it possible, that MyTcpClient.GetStream().Read() returns only < 128 Bytes, although all messages from client-side are exactly 128 bytes long?

I guess that such a client message is short enough to fit into one packet on the tcp/ip layer – but could there be some kind of fragmentation or random although?

Is NetworkStream.DataAvailable the right attribute to defend against this?

After running smoothly for hours, i sometimes get strange errors and connection losses, that point to something like that.

Thanks in advance.

  • 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-05-20T21:53:42+00:00Added an answer on May 20, 2026 at 9:53 pm

    Is it possible, that MyTcpClient.GetStream().Read() returns only < 128 Bytes

    Yes. You can’t assume your call to Read( ) will return 128 bytes.

    see the docs:

    The total number of bytes read into
    the buffer. This can be less than the
    number of bytes requested if that many
    bytes are not currently available, or
    zero (0) if the end of the stream has
    been reached.

    See this link on how to properly read from streams

    Try something like this instead: (pass in a 128 length byte array)

    private static void ReadWholeArray (Stream stream, byte[] data)
        {
            int offset=0;
            int remaining = data.Length;
            while (remaining > 0)
            {
                int read = stream.Read(data, offset, remaining);
                if (read <= 0)
                    throw new EndOfStreamException 
                        (String.Format("End of stream reached with {0} bytes left to read", remaining));
                remaining -= read;
                offset += read;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've got a Python-based web server that unpickles a number of large data files
I've got a node.js Connect server that checks the request's cookies. To test it
Let's say I've got a SQL Server table that logs user activity. Let's say
First,I uploaded a file in a external server and got a url from that
We've got a Windows Server 2003 running IIS 6 where we host multiple sites
i have a node.js server that i want to be able to handle exceptions
function do_post_request($url, $data, $optional_headers = null) { $request = new HttpRequest($url, HttpRequest::METH_POST); $request->setBody($data); $response
I've got an oob app with a webbrowser on it. The webbrowser source is
I'm searching for a library / framework / codesnippet that helps me build a
Is there a well-established way to share Ant targets between projects? I have a

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.