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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:59:56+00:00 2026-05-31T09:59:56+00:00

I have the following code: private string Connect() { string responseData; try { TcpClient

  • 0

I have the following code:

private string Connect()
{
    string responseData;

    try
    {
        TcpClient client = new TcpClient(ServerIp, Port);
        client.ReceiveBufferSize = Int32.MaxValue;

        Byte[] data = Encoding.GetEncoding(1251).GetBytes(ReadyQuery);


        NetworkStream stream = client.GetStream();

        // send data
        stream.Write(data, 0, data.Length);


        // buffer
        data = new Byte[65536];               

        Int32 bytes = stream.Read(data, 0, data.Length);
        responseData = Encoding.GetEncoding(1251).GetString(data, 0, bytes);                

        // close all
        stream.Close();
        client.Close();
        return responseData;
    }

I have problem with a big message. The receive message size is 22K chars. I get only part of message.
How can I receive big messages?

PS. In the debugger bytes equal 4096.

  • 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-31T09:59:58+00:00Added an answer on May 31, 2026 at 9:59 am

    You call stream.Read in a loop until you read the entire message. If you know the message size in advance it’s relatively easy:

    int messageSize = 22000;
    int readSoFar = 0;
    byte [] msg = new byte[messageSize];
    
    while(readSoFar < messageSize)
    {
        var read = stream.Read(msg, readSoFar, msg.Length - readSoFar);
        readSoFar += read;
        if(read==0)
            break;   // connection was broken
    }
    

    If the message size is part of the message (say, encoded in the first 4 bytes), you should read those first and then do as I suggested.

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

Sidebar

Related Questions

I have the following code: [DataContract] class TestContract { private String _Name; private Int32
So, I have the following code: private readonly Dictionary<string, IGame> _gameLookup = new Dictionary<string,
I have the following code: private SetMultimap<String, Dynamic> dynamicFields = TreeMultimap.create(Ordering.natural(), new Comparator<Dynamic>() {
I have the following code: private static final Set<String> allowedParameters; static { Set<String> tmpSet
I have the following code private Map<KEY, Object> values = new HashMap<KEY, Object>(); public
I have the following code: private ActionResult Foo(string format, IEnumerable<String> myResults) { if (format
Hi I have some strings generated using the following code: private static string CalcHashCode(byte[]
I have the following code: private void Process(string path) { using (FileStream fs =
I have the following code - private static void convert() { string csv =
I have the following code: private bool IsMousetrapFile(string path) { logger.Log(validateFileMessage + path); Excel.Application

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.