• Advertisement
Sign in to follow this  

issues with sockets

This topic is 4216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am writing something like a proxy server and having some issues when I send the request back to browser. THe browser doesn't seem to show up the data immediates. Is there way to actually force the browser to display what is sent back to it? This is my basic code :-
   while(1)
   {
      fgets(tmp, 100, fp);
      if(strstr(tmp, "Connection: keep-alive") != NULL)
      {
         strcpy(tmp, "Connection: close\r\n");
      }

      strcat(buf, tmp);
      if(newsize >= fileSize) break;
      newsize += 100; 
   }

   int newLen = strlen(buf);
   fprintf(stderr, "Writing from cache\n");
   write(browserSock, buf, fileSize + 1);
   fprintf(stderr, "Wrote from cache\n");

Thanks and regards

Share this post


Link to post
Share on other sites
Advertisement
A couple of things come to mind:

  1. What version of HTTP are you using? I think in 1.0 it is the server's (i.e. yours in this case) responsibility to close the connection, and the page is not thought of as 'complete' until the connection is closed. Though most browsers will display part-opened content, there's no requirement for them to do so, and certainly not immediately.
  2. Are you sending correct HTTP data? Have you attached a text viewer to the output and given it a sanity check? (In particular, what about the Content-Length attribute?)
  3. Is buf big enough to take everything you put in it? Does it always have fileSize+1 bytes set (think about what happens with that string replacement)? What if you read 100b more than you expect?
  4. Code tidiness: why is 100 a 'magic number', and why are you not using std::string (is this C code instead of C++)?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement