LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Implement persistent HTTP connection (https://www.linuxquestions.org/questions/programming-9/implement-persistent-http-connection-382363/)

syseeker 11-12-2005 03:46 AM

Implement persistent HTTP connection
 
Hi,

I need some hints on how to code persistent HTTP connection using C socket programming.


I have studied mini-httpd and thttpd, but realize that perhaps they didn't implement this feature. I have analysed the packets exchanged between a HTTP client and mini-httpd server using ethereal.

The client initiates a request by first sending HTTP HEAD. Upon receiving, the mini-httpd sends HTTP response 200 OK and subsequently close connection. The client is supposed to send HTTP GET, but upon closing of connection, the entire HTTP transaction stop.

thttp has the same output. It seems that mini-httpd/thttp do not support persistent HTTP connection, which allow multiple request and response in one TCP connection establishment.

I have tested with mini-httpd by commenting out close(conn_fd) in main(), it turns out that the server does not initiate connection close, and the client is able to send a HTTP GET. But upon receiving HTTP GET request, mini-httpd shows errno=ENOSOCK in the main loop, and the server does not fork a new sub-process to handle HTTP GET request. So the client RST at timeout and stop.

As there is no way to change the implementation of HTTP client, I am seeking possibility to change mini-httpd/thttpd to support persistent connection. Does anybody has already enhance this feature in mini-httpd/thttpd? or perhaps some hints on how to code is truely appreciated.

Or is there any existing open source small HTTP web server that implement persistent HTTP connection? Apache is just too huge and complex. BTW, some hints on apache's code on implementing persistent HTTP is also appreciated. :study:

Thank you.

paulsm4 11-12-2005 08:55 PM

Http was *designed* to be stateless!

For excellent technical reasons (for example, "scalability").

That's why you saw the results you did in your experiments. And that's also why "cookies" (and other, arguably better) mechanisms for maintaining state (in an inherently stateless protocol) were invented.

I'm guessing that you want "persistence" for maintaining session state. If, instead, you're just worried about the performance issues of establishing and breaking down TCP/IP connections ... trust me. It's *NOT* an issue!

But either way: if your interest is semantic (maintaining state) or performance (pooling TCP/IP connections)), please consider browsing around W3C.org:

http://www.w3c.org

They'll give you more background on the whys/wherefores of HTTP design, and some good alternate design ideas for the problem you're trying to solve.

For example:

http://www.w3.org/Protocols/Specs.html

... or ...

http://www.w3.org/Consortium/faq

PS:
You might also want to look at "Jigsaw" for some ideas on a rather "object-oriented" next-generation web server design:

http://www.w3.org/Jigsaw/Doc/FAQ.html#purpose


primo 11-12-2005 11:29 PM

Search por HTTP pipelining:
http://www.mozilla.org/projects/netl...ining-faq.html

syseeker 11-30-2005 01:18 AM

http://xoomer.virgilio.it/adefacc/ht...tpd/index.html

I found this version thttpd which support persistent connection.


All times are GMT -5. The time now is 11:31 PM.