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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:22:00+00:00 2026-05-12T05:22:00+00:00

I am trying to transfer an image using TCP sockets using linux. I have

  • 0

I am trying to transfer an image using TCP sockets using linux. I have used the code many times to transfer small amounts but as soon as I tried to transfer the image it only transfered the first third. Is it possible that there is a maximum buffer size for tcp sockets in linux? If so how can I increase it? Is there a function that does this programatically?

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

    TCP sends the data in pieces, so you’re not guaranteed to get it all at once with a single read (although it’s guaranteed to stay in the order you send it). You basically have to read multiple times until you get all the data. It also doesn’t know how much data you sent on the receiver side. Normally, you send a fixed size “length” field first (always 8 bytes, for example) so you know how much data there is. Then you keep reading and building a buffer until you get that many bytes.

    So the sender would look something like this (pseudocode)

    int imageLength;
    char *imageData;
    
    // set imageLength and imageData
    
    send(&imageLength, sizeof(int));
    send(imageData, imageLength);
    

    And the receiver would look like this (pseudocode)

    int imageLength;
    char *imageData;
    
    guaranteed_read(&imageLength, sizeof(int));
    imageData = new char[imageLength];
    guaranteed_read(imageData, imageLength);
    
    void guaranteed_read(char* destBuf, int length)
    {
        int totalRead=0, numRead;
        while(totalRead < length)
        {
            int remaining = length - totalRead;
            numRead = read(&destBuf[totalRead], remaining);
            if(numRead > 0)
            {
                totalRead += numRead;
            }
            else
            {
                // error reading from socket
            }
        }
    }
    

    Obviously I left off the actual socket descriptor and you need to add a lot of error checking to all of that. It wasn’t meant to be complete, more to show the idea.

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

Sidebar

Related Questions

I'm trying to transfer the contents of one list to another, but it's not
I have be trying to figure out what is wrong but every time i
Ultimately I'm trying to transfer buffers from one machine to another. The code below
I have an issue where I'm trying to transfer a large number of objects
I am trying to implement a udp image transfer program in java. The sender
I'm trying to securely transfer files between 2 devices, so I'm using an SslStream
Im trying to transfer a string-variable to another page. In Main Page code looks
What i'm trying to do is transfer an image from the web service to
my script is using utf8_general_ci and im trying to transfer to another script that
I have a scripted SQL Server Agent job I'm trying to transfer over to

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.