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");
issues with sockets
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 :-
Thanks and regards
A couple of things come to mind:
- 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.
- 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?)
- 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?
- Code tidiness: why is 100 a 'magic number', and why are you not using std::string (is this C code instead of C++)?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement