1

What does "respond to client" mean? What should I do to respond to a browser?

And, should I use "printf" to print out the response?

Another problem is, when I refresh the browser, my program concatenate the absolute-path to

the root again, for example:

the first time(root + absolute-path):/home/jharvard/Dropbox/pset6/public/cat.jpg

and when I refresh the browser,it becomes:/home/jharvard/Dropbox/pset6/public/cat.jpg/cat.jpg,

if refresh again, it will be:/home/jharvard/Dropbox/pset6/public/cat.jpg/cat.jpg/cat.jpg......so forth

I don't know why that would happen, and I think there should be some functions or something

that will reset the root each time we iterate the loop again...

Need some help, thanks!!

2

when you look a few lines above you see how the code is responding to a php page request. Just do the same - and add a dprintf for Content-Type.

        // respond to client
        if (dprintf(cfd, "HTTP/1.1 200 OK\r\n") < 0)
        {
            continue;
        }
        if (dprintf(cfd, "Connection: close\r\n") < 0)
        {
            continue;
        }
        if (dprintf(cfd, "Content-Length: %i\r\n", length) < 0)
        {
            continue;
        }
        if (write(cfd, body, size) == -1)
        {
            continue;
        }

the refreshing your browser problem is a problem on how you determine the path.

1
  • OK, thanks, that helps. – Y_C Feb 23 '15 at 8:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .