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 6024773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:12:15+00:00 2026-05-23T04:12:15+00:00

I have the following code to read messages sent from a server to the

  • 0

I have the following code to read messages sent from a server to the client:

while (true) {
    byte[] readBuffer = new byte[327680];
    StringBuilder message = new StringBuilder(327680);
    while (true) {
        do {
            int bytes = ServerStream.Read(readBuffer, 0, readBuffer.Length);
            message.AppendFormat("{0}", Encoding.ASCII.GetString(readBuffer, 0, bytes));
        }
        while (ServerStream.DataAvailable);

        if (message.Length > 0) {
            foreach (string msg in message.ToString().Split(MESSAGE_END)) {
                if (msg != "") ProcessServerMessage(msg);
            }
            message.Clear();
            readBuffer = new byte[327680];
        }
    }
}    

Unfortunately… Every now and then the variable ‘message’ appears to chop off, for no reason I can understand. I’ve made the read buffer huge, to see if that was the issue, but it doesn’t help. It seems to happen when the server sends lots of data at once, but nowhere near 327680 bytes…

Also, when checking the server logs, it appears to be sending the data completely, un-chopped. It’s like half the info is ‘lost’ on the internet somewhere… But this is TCP, so that shouldn’t happen, right?

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-23T04:12:16+00:00Added an answer on May 23, 2026 at 4:12 am

    It’s not lost, you’re not doing buffered reading correctly. Even though you’re checking DataAvailable, odds are that the sender hasn’t flushed that data yet. So it’s “on the way” (waiting to be sent), but DataAvailable will return false because it hasn’t yet arrived.

    It’s always better to send an integer ahead of the data so that the receiver knows how much data to expect, OR to look for some kind of terminator (null, newline, something).

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

Sidebar

Related Questions

I have got the following code from here to read an Excel file using
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I have the following code: String inputFile = somefile.txt; FileInputStream in = new FileInputStream(inputFile);
I have the following code to send a (file) stream to a wcf client:
I have used the module Mail::Webmail::Gmail to read the new messages in my Gmail
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS site.

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.