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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:46:26+00:00 2026-05-12T19:46:26+00:00

In C (UNIX), how can I transfer and receive a file in multiple blocks

  • 0

In C (UNIX), how can I transfer and receive a file in multiple blocks using a socket?

For example, if I had a file of 1234 bytes, and a block size of 500, I would transfer:

  • 500 bytes,
  • then 500 bytes,
  • then 234 bytes

I have attempted this using fseek, read, write, but I just cannot get the logic right. Even a good reference would be much appreciated.

My socket routines are:

int readn(sd, chunk, bytesToRead);

int writen(sd, chunk, bytesToWrite);
  • 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-12T19:46:26+00:00Added an answer on May 12, 2026 at 7:46 pm

    If you’re using TCP then all you need to do is send your data block (I assume you have some kind of protocol which tells you how many bytes are in the block, such as a header?) and when you get your block at the other end simply write it to the file that you are writing to. TCP will deal with making sure everything is arriving in the expected order so you should just be able to walk your way through the file reading in X bytes at a time and sending them and then on the recv side you simply recv your data and write it to the file… Just remember that every read you issue on your socket can return anywhere between 1 and “block size” bytes and that your protocol should be able to tell you how many to expect and that you should then loop until you have actually got as many bytes as you’d expect…

    If you’re using UDP then things get a little more fun as you need to track which block a particular datagram represents…

    Homework question?

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

Sidebar

Related Questions

The UNIX sort command can sort a very large file like this: sort large_file
Can I authenticate a local Unix users using C? If so does anyone have
In the Unix shell I can do this to empty a file: cd /the/file/directory/
Can I run the batch file on UNIX? (Linux / Mac OS X) I
I am trying to transfer a large (~3GB) file between two unix machines. I
On Unix one can have single socket used for both IPv6 and IPv4 (
In some unix flavours you can emulate a slow network connection to, say 4KB/s
How can I tell unix find to include in it's recursive search a folder
How can I convert from a unix timestamp (say 1232559922) to a fractional julian
How can I compile/run C or C++ code in a Unix console or a

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.