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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:00:44+00:00 2026-05-26T05:00:44+00:00

I have an application that constantly fetches input in Java from a frame buffer

  • 0

I have an application that constantly fetches input in Java from a frame buffer and sends it over the wire to a C++ application.

I am having issues on the receiver side. I am trying to send one packet (or at least let TCP reconstruct it as a single packet) for each frame buffer. The frame buffer is getting splitted into multiple small packets on the receiving end.

The Java code is the following:

OutputStream os = clientSocket.getOutputStream();
FileInputStream fos = new FileInputStream("fb");
while (true) {
    int nb = fos.read(buff);
    if (nb <= 0)
        break;
    os.write(buff, 0, nb);
}
fos.close();
os.close();

On the client side, I am trying to read the same amount. nb and size are the same value here:

n = read(sockfd, buffer, size);
while (n > 0) {
    // We have a new frame
    fprintf(stderr, "New frame: %d\n", n);

    n = read(sockfd, buffer, size);
}

The value of n that is printed is much smaller than size. It receives a lot of packets when I would hope the return from read() would be a packet of the size ‘size’ (or nb).

Does anyone please know why is that please?

Thank you very much for your help!

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

    You don’t have control over TCP frame sizes. Network devices can and do fragment packets so that you will receive more packets than you sent.

    The word “stream” is used for a very good reason. You are getting a stream of bytes but there is no framing unless the sender and receiver application impose framing on the stream by including frame markers in the data. One common way used by a lot of TCP protocols is to use \r\n as a frame marker. This means that the receiver collects incoming data but does not process it until it encounters a frame marker. At that point, the receiver processes one frame and then goes on looking for the next frame marker.

    One thing that you should consider is using a cross-platform cross-language library like ZeroMQ to handle framing for you.

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

Sidebar

Related Questions

I have an application that sends messages to an external web service. I build
I have an application that sends the customer to another site to handle the
I have an application that's a mix of Java and C++ on Solaris. The
I have an application that needs to constantly (every 50ms), call to an MVC
I have an installer of an application that needs to install over any existing
I have an application that processes data from bluetooth and send it to the
I have an application that is running as a background service and constantly listens
I have an application that displays an image inside of a Windows Forms PictureBox
I have an application that reads a CSV file with piles of data rows.
I have an application that uses NHibernate as its ORM and sometimes it experiences

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.