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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:34:19+00:00 2026-06-17T03:34:19+00:00

I need to send data across to the socket, basically transferring a file ,

  • 0

I need to send data across to the socket, basically transferring a file ,

According to send() function docs, it says,

If no error occurs, send returns the total number of bytes sent, which can be less than the number requested to be sent in the len parameter. Otherwise, a value of SOCKET_ERROR is returned,

The line that I am worried about is, the return value may be less than requested value.
Because I am reading from a file and writing to a socket, because it may not send all the bytes, I guess I would have to retry if the full buffer was not sent ? in which case I guess I would have to somehow advance the pointer on the same buffer by bytes read and send it again ??

I just want know if that’s the way about it ? or is there a much clever way to it, so that all the requested data gets sent without me having to worry about when not all data was sent ?

Thanks,

  • 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-06-17T03:34:21+00:00Added an answer on June 17, 2026 at 3:34 am

    Yes, you have to advance the buffer pointer and repeat the send call until either the entire buffer is consumed or you get a hard error. The standard idiom looks something like this:

    int
    send_all(int socket, const void *buffer, size_t length, int flags)
    {
        ssize_t n;
        const char *p = buffer;
        while (length > 0)
        {
            n = send(socket, p, length, flags);
            if (n <= 0)
                return -1;
            p += n;
            length -= n;
        }
        return 0;
    }
    

    Note that if you are sending datagrams whose boundaries matter (e.g. UDP) you cannot use this technique; you have to treat a short send as a failure.

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

Sidebar

Related Questions

I have a scenario where I need to send a series of data across
I need to send data to a hardware device over serial port. I'm using
I need to send some data with radio button. This buttons are <td> <span
I need to send XML data to a URL. The XML data is contained
In a project for school I need to send xml data to the client
I have an html form. I need to send its data to flash on
i need to send and receive data to/from a microcontroller using java using usb
Ok i need to use json on my iOS application to send/receive data to/from
I am calculating 16 bit checksum on my data which i need to send
I need to read from NetworkStream which would send data randomly and the size

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.