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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:24:54+00:00 2026-05-28T06:24:54+00:00

I have problem with reading buffer, when reading is not completed. If the received

  • 0

I have problem with reading buffer, when reading is not completed.

If the received XML data is valid, then I have no problem. But when the received XML data is not correct then I am waiting for the second part of the data, and there I get an error.

My code looks like:

int currentDataSize = socket.EndReceive(iar);
string currentData  = convertToString(buffer, currentDataSize);

if (IsValidXml(currentData))
{
  //Here I am parsing the xml data and writing into the sql db.
  runParseWorker(currentData);      

  //Here I am sending the xml-data to all clients.
  runSendWorker(currentData);

  //Here I am calling the BeginRecieve Method again.
  socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, 
                      new AsyncCallback(dataRecievedCallback), null);
}
else
{ 
  //It gives error when I use offset..
  socket.BeginReceive(buffer, currentDataSize, buffer.Length, SocketFlags.None, 
                      new AsyncCallback(dataRecievedCallback), buffer);
}

How can I get the rest of the data and how do I use offset correctly?

I am getting this error:

specified argument was out of the range of valid values. parameter name : size
  • 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-28T06:24:55+00:00Added an answer on May 28, 2026 at 6:24 am
      socket.BeginReceive(buffer, currentDataSize, buffer.Length, SocketFlags.None, 
                          new AsyncCallback(dataRecievedCallback), buffer);
    

    If you use an offset, the data you receive will be stored in the buffer starting at the specified offset, so you need an array of size offset + length. In your case just adjust the length to correctly indicate how many bytes you can store (buffer.Length - currentDataSize):

      socket.BeginReceive(buffer, currentDataSize, buffer.Length - currentDataSize, SocketFlags.None, 
                          new AsyncCallback(dataRecievedCallback), buffer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem involves checking if I have a valid database connection before reading from
I have a problem reading a txt file to insert in the mysql db
I have a problem with reading some gml files in c#. My files do
i have been reading about multiple inheritance What is the exact problem with multiple
I have problem when I try insert some data to Informix TEXT column via
I have a problem with the boost::asio::serial_port class reading from a GPS device (USB-Serial).
I have been reading articles about clipping now for hours now but I dont
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am

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.