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

  • Home
  • SEARCH
  • 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 8795539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:24:34+00:00 2026-06-13T23:24:34+00:00

int main(int argc, char *argv[]) { int conn_s = socket(AF_INET, SOCK_STREAM, 0); struct addrinfo

  • 0
int main(int argc, char *argv[]) {

    int conn_s = socket(AF_INET, SOCK_STREAM, 0);
    struct addrinfo hints;
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = 0;

    struct addrinfo *addr = (struct addrinfo *) calloc(1, sizeof(struct addrinfo));

    getaddrinfo("google.com", "80", &hints, &addr);

    connect(conn_s, addr->ai_addr, sizeof(struct sockaddr_in));

    char *http_request = "GET / HTTP/1.1\n\n";

    send(conn_s, http_request, strlen(http_request), 0);
    FILE *sockfile = (FILE *) fdopen(conn_s, "r");
    FILE *fp = fopen("/Users/leekaiwei/Desktop/results.html", "w+");
    int ch;

    while ((ch = fgetc(sockfile)) != EOF) {
        fprintf(fp, "%c", ch);
    }

    close(conn_s);
    fclose(fp);
    fclose(sockfile);
    free(addr);
    return 0;
}

The while loop never ends. Why is this? I have done this with a local file and it works fine. It also works fine with a for loop, it’s just that the fgetc() never returns EOF.

  • 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-13T23:24:35+00:00Added an answer on June 13, 2026 at 11:24 pm

    HTTP/1.1 defaults to connection: keepalive, so like simonc said, the server is actually waiting for you to make the next request, and will wait until a server-dependent timeout.
    Use HTTP/1.0 to get EOF.

    FWIW: it took 245 seconds to complete.

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

Sidebar

Related Questions

This is my program: int main(int argc, char *argv[]){ if(argc != 2){ printf(Uso: ./server
This is my code: int main(int argc, char *argv[]){ FILE *fp; char *tmp, *tmp2,
I have the following code: int main(int argc, char** argv) { onelog a; std::cout
See this example! int main( int argc, char ** argv ) { int *ptr
I have a, int main (int argc, char *argv[]) and one of the arguements
hej.h void hej(); hej.m void hej(){} main.mm #import hej.h int main(int argc, char *argv[])
#include <stdio.h> int main(int argc, char *argv[]) { long* fp; while(1) { fp =
Following simplified code snippet: #include <QtGui> int main(int argc, char **argv) { QApplication app(argc,
I am running this code: #include <iostream> #include <cstddef> int main(int argc, char *argv[]){
#include<stdio.h> #include<math.h> int main(int argc, char **argv){ // read in the command-line argument double

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.