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 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

I got a web DMZ server, that hosts an Extranet ASP.NET application. I want
i got a server host that only let me upload files through ftp (with
I have got a Client/Server Application that using Asynchronous Socket.My problem is i cant
I've got a web server that sends email (from IIS 5.1) to clients throughout
We've got a Java server application that runs on a number of computers, all
I've got a server that loads an html page by echoing the result of
I've got bonobo git server that's supposed to handle syncing among at least 2
I got an app running on my SQL Server that is starting to slow
I've got a T-SQL stored procedure running on a Sybase ASE database server that
We've got a regular (i.e. not extended) stored procedure in SQL Server 2000 that

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.