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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:19:53+00:00 2026-05-22T20:19:53+00:00

I’m writing a small networking program in C++. Among other things it has to

  • 0

I’m writing a small networking program in C++. Among other things it has to download twitter profile pictures. I have a list (stl::vector) of URLs. And I think that my next step is to create for-loop and send GET messages through the socket and save the pictures to different png-files. The problem is when I send the very first message, receive the answer segments and save png-data all things seems to be fine. But right at the next iteration the same message, sent through the same socket, produces 0 received bytes by recv() function. I solved the problem by adding a socket creation code to the cycle body, but I’m a bit confused with the socket concepts. It looks like when I send the message, the socket should be closed and recreated again to send next message to the same server (in order to get next image). Is this a right way of socket’s networking programming or it is possible to receive several HTTP response messages through the same socket?

Thanks in advance.

UPD: Here is the code with the loop where I create a socket.

    // Get links from xml.
    ...
    // Load images in cycle.
    int i=0;
    for (i=0; i<imageLinks.size(); i++)
    {
        // New socket is returned from serverConnect. Why do we need to create new at each iteration?
        string srvAddr = "207.123.60.126";
        int socketImg = serverConnect(srvAddr);
        // Create a message.
        ...
        string message = "GET " + relativePart;
                message += " HTTP/1.1\r\n";
        message += "Host: " + hostPart + "\r\n";
        message += "\r\n";
        // Send a message.
        BufferArray tempImgBuffer = sendMessage(sockImg, message, false);
        fstream pFile;
        string name;
        // Form the name.
        ...
        pFile.open(name.c_str(), ios::app | ios::out | ios::in | ios::binary);
        // Write the file contents.
        ...
        pFile.close();
        // Close the socket.
        close(sockImg);
    }
  • 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-22T20:19:54+00:00Added an answer on May 22, 2026 at 8:19 pm

    The other side is closing the connection. That’s how HTTP/1.0 works. You can:

    • Make a different connection for each HTTP GET
    • Use HTTP/1.0 with the unofficial Connection: Keep-Alive
    • Use HTTP/1.1. In HTTP 1.1 all connections are considered persistent unless declared otherwise.

    Obligatory xkcd link Server Attention Span

    Wiki HTTP

    The original version of HTTP
    (HTTP/1.0) was revised in HTTP/1.1.
    HTTP/1.0 uses a separate connection to
    the same server for every
    request-response transaction, while
    HTTP/1.1 can reuse a connection
    multiple times

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put

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.