Why does this simple web client hang

Discussion in 'Computer Programming, Emulation, and Game Modding' started by StackMasher, Mar 9, 2017.

  1. StackMasher

    StackMasher GBAtemp Regular

    Nov 29, 2016
    I'm learning networking and sockets so I decided to test my skills by writing a client. It just hangs for some reason:
    #include <sys/socket.h>
    #include <arpa/inet.h>
    #include <unistd.h>
    #include <cstring>
    #include <iostream>
    const char* request = "GET http://www.imdb.com/index.html HTTP/1.0";
    int main()
       int sock = socket(AF_INET, SOCK_STREAM, 0);
           if (sock<1)
               throw "Failed to create a socket";
           sockaddr_in session;
           session.sin_port = htons(80);
           session.sin_family = AF_INET;
           session.sin_addr.s_addr = inet_addr("");
           if (connect(sock, (sockaddr*)&session, sizeof(session)) < 0)
               throw "Failed to establish a connection";
           send(sock, request, strlen(request), 0);
           char buf[1000];
           recv(sock, buf, 1000, 0);
           for (int i{}; i<1000; ++i)
              std::cout << buf[i];
       catch (const char* exc)
           std::cerr << "An error occured: " << exc << std::endl;
    Any idea why? (I'm aware of the buffer overflow vuln this is just a quick and dirty program)
    Last edited by StackMasher, Mar 9, 2017
  2. th3_r3v

    th3_r3v Newbie

    Apr 6, 2017
    United States
    @StackMasher . I would guess it's got something to do with just the GET request outside of a regular 'browser'/client. I tired to perform a simple GET as well with an online tool. I got the same response, a long hang.

    In the end, I did receive a report of all the http transactions, but none were executed. Just an fyi. I would guess by looking at the drive-by DL tree that you have close to 200 transactions trying to run, which maybe locking your client as well.

    Attached Files:

  3. evandixon

    evandixon PMD Researcher

    May 29, 2009
    United States
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice