Receiving content

This is a discussion on Receiving content within the Windows Programming forums, part of the Platform Specific Boards category; I use this code to receive the results of my HTTP request: Code: int l; char abc[100000]; char p[1024]; while((l=recv(sock,p,1023,0))>0){ ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Receiving content

    I use this code to receive the results of my HTTP request:
    Code:
         int l;
         char abc[100000];
         char p[1024];
         while((l=recv(sock,p,1023,0))>0){
             cout.write(p,l);
             p[l] = '\0';
             strcpy(abc,p);
         }
    It displays all the content, but after it had showed all the content it just hangs. Anything after that doesn't work. I removed unnecessary things but it still doesn't work correctly:
    Code:
         int l;
         char p[1024];
         while((l=recv(sock,p,1023,0))>0){
             cout.write(p,l);
         }
    Why?
    Last edited by maxorator; 12-14-2005 at 06:35 AM.

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    Well, if it uses HTTP 1.0, then the connection will close when the data is sent, so recv will return a -1, this should work just fine with your code. However, if you specify HTTP 1.1, the connection may remain open after the full data has been recieved and if the connection remains open, recv will block while waiting for more data. If this is the case, you need to read the Content-Length header and after the "\r\n\r\n" that separates the header from the data, you read Content-Length number of bytes only. I would suggest that you just specify "GET /whatever HTTP/1.0" as your request string.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Yes, I believe that's the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Memory Content Question
    By azzuwan in forum C Programming
    Replies: 7
    Last Post: 09-18-2008, 05:23 AM
  2. Replies: 1
    Last Post: 03-21-2008, 09:15 PM
  3. Library which extract html tags content
    By Bargi in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2007, 11:17 PM
  4. How do I delete the content of a char && string ??
    By client in forum C Programming
    Replies: 2
    Last Post: 06-01-2002, 06:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21