Sign in to follow this  
CRACK123

issues with sockets

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this