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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:46:45+00:00 2026-05-28T05:46:45+00:00

I have some C++ code that is writing to a socket that is being

  • 0

I have some C++ code that is writing to a socket that is being read from by a Java program.

The C++ program uses boost::async_write to transfer the bytes, and they are then read by the Java program. The first 4 bytes of the async_write call correspond to the size of the underlying data segment. Because the size is explicitly determined by this header, the Java code can fill a byte array that is the size of the actual data using a BufferedInputStream’s “read” method.

Although this seems to work fine almost every time, sometimes the byte array read by the InputStream contains zeroed out data for the end of its buffer. About 1 out of every 50000 messages is “corrupted” in this way. The place in the buffer where the zeroed out data starts varies. Although I can catch this and throw out the message I am wondering if this is expected performance? I have tried this where both programs are communicating through a socket on localhost and still have the problem.

I do not believe the bytes being written in the C++ program are going out of scope, because the are temporarily stored on a queue until the “handle_write” returns (from the async_write)

The C++ program only has a single thread executing the io_service.

The Java program is executing the reading in a single thread as well.

I did not detect any memory leaks in either program.

  • 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-28T05:46:46+00:00Added an answer on May 28, 2026 at 5:46 am

    Most likely, this bug is on the reading side. Are you sure you actually read the entire message?

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

Sidebar

Related Questions

I have some code that uses the shared gateway pattern to implement an inversion
I have some code that effectively does this : File file = new File(C:\\Program
I have some code that uses the Oracle function add_months to increment a Date
I have some java code that looks similar to this: private void startServer() throws
I have some vb6 code that is stubbornly writing to Windows-1252. Open fileName For
I have some python code that: Takes a BLOB from a database which is
I have some code that gives a user id to a utility that then
I have some code that raises PropertyChanged events and I would like to be
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have some code that generates image of a pie chart. It's a general

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.