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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:16:03+00:00 2026-06-14T03:16:03+00:00

This is Data Receiving functionality Code from http server, Perfectly Working.. But i want

  • 0

This is Data Receiving functionality Code from http server, Perfectly Working.. But i want to add pause and Resume to this function..
can anybody suggest me how to do that ??
Note: Ignore variable Declaration.

int rest=0,size=0,count=0;                               
memset(buffer,'\0',sizeof(buffer));
do {
    rc=read(sockfd,buffer,1500);                  //Reading from socket connection
    if(rest==0)
    {   /*Extracting Content length*/
        data=strstr((char*)buffer,"Content-Length"); 
        if(data!=NULL)
        {
            value=atoi((char*)data+15);data_rest=value;
            rest=1;
        }
    }
    if(count==0)
    {   /*Extracting Header*/
        content=strstr(buffer,"\r\n\r\n");
        if(content!=NULL)
        { 
            printf("FOUND Header END\n");
            content=content+4;count=1;
            /*copying DATA to the file which has same Extension*/
            data_wrote=fwrite(content,sizeof(char),rc-(content-buffer),fp);
        }
    }
    else
    {
        content=buffer;
        /*copying DATA to the file which has same Extension*/
        data_wrote=fwrite(content,sizeof(char),rc,fp);
    }
    size=size+rc;
    total_wrote=total_wrote+data_wrote;
    printf("Total size = %d\n",size);

    memset(buffer,'\0',sizeof(buffer));
} while(rc>0);  /*until end of file*/
  • 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-14T03:16:04+00:00Added an answer on June 14, 2026 at 3:16 am

    Here is the process I would use:

    • Send the initial request with Range: bytes=0- HTTP/1.1 request header.
      If the server responds with a HTTP/1.1 206 Partial content, you know you can resume the connection later.
      Save the ETag response header, as it should stay unmodified unless the content on the server changes, and/or the Content-Type, and Last- Modified headers.
      Note that the Content-Range response header specifies the offsets of the bytes in this response, with the final number being the total length of the full content, and Content-Length only specifies the length of the current response (not the length of the original content).

    • Interrupt the transmission by simply closing the connection.

    • Send the continuation request with Range: bytes=N- HTTP/1.1 request header, where N is the offset to the first byte still missing from the local copy.
      If the server does not respond with a HTTP/1.1 206 Partial content, you have no recourse but have to download the entire content again (using normal HTTP request processing).
      If the ETag, Content-Type, or Last-Modified response headers mismatch, then it is possible the content was modified on the server, and you should drop this connection and download the full request instead.
      The Content-Range response header specifies the offsets of the bytes in this response, with the final number being the total length of the full content, and Content-Length only specifies the length of the current response (not the length of the original content).

    In all cases it is possible the server uses the chunked content transfer encoding, so you must be prepared to handle that, toom since the request is HTTP 1.1. See the RFC2616 for details.

    When you test this, I recommend you use a simple Bash script to connect to some URL using your custom headers, and to output the response headers to standard error and message content to standard output:

    #!/bin/bash
    
    Host="localhost"   # Host name, use your own servers
    Port="80"
    Query="/"          # Path to the content requested
    Range="0-"         # Byte range requested
    
    # Open up a connection
    exec 3<>/dev/tcp/$Host/$Port || exit $?
    
    # Set up a reader sub-shell that will flush the headers
    # to standard error, and content to standard out.
    (   Headers=1
        while read Line ; do
            Line="${Line//$'\r'/}"
            if [ -z "$Line" ]; then
                Headers=0
            elif [ $Headers -gt 0 ]; then
                printf '%s\n' "$Line" >&2
            else
                printf '%s\n' "$Line"
            fi
        done
        exit 0
    ) <&3 &
    
    # Construct a byte-range request:
    Request=""
    Request="$Request""GET $Query HTTP/1.1"$'\r\n'
    Request="$Request""Host: $Host"$'\r\n'
    Request="$Request""Range: bytes=$Range"$'\r\n'
    Request="$Request""Connection: close"$'\r\n'
    
    # Do a normal request.
    printf '%s\r\n' "$Request" >&3
    
    # Close the connection (the read end is still open).
    exec 3>&-
    
    # and wait for the request to complete.
    wait
    

    The above is not a HTTP client, and does not do chunked transfers, for example; it is just a debugging tool you can use to see exactly the data that flows from the server to the client side.

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

Sidebar

Related Questions

I am accessing this data from a web server using NSURL, what I am
I am receiving data from a server through a socket using boost asio, and
I have one thread that is receiving data over a socket like this: while
Why am I receiving this Rake error: $ rake --version /Volumes/Data/sampablokuper/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not
i Want to fetch this data using json decode. Please Help.. So far i
I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I'm receiving some data from a ZODB (Zope Object Database). I receive a mybrains
I am receiving data from a web service and its replying me data in
I am receiving XML data from a service. The test data I am receiving
This is the sample data receiving to the php script [{id:1,due_date:2011-09-03,due_amount:48279.00,wo_interest:45980.00}, {id:2,due_date:2011-10-03,due_amount:48279.00,wo_interest:45980.00}] and the

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.