LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-12-2005, 03:46 AM   #1
syseeker
Member
 
Registered: Aug 2003
Posts: 66

Rep: Reputation: 15
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.

Thank you.
 
Old 11-12-2005, 08:55 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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


Last edited by paulsm4; 11-12-2005 at 09:12 PM.
 
Old 11-12-2005, 11:29 PM   #3
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Search por HTTP pipelining:
http://www.mozilla.org/projects/netl...ining-faq.html
 
Old 11-30-2005, 01:18 AM   #4
syseeker
Member
 
Registered: Aug 2003
Posts: 66

Original Poster
Rep: Reputation: 15
http://xoomer.virgilio.it/adefacc/ht...tpd/index.html

I found this version thttpd which support persistent connection.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C(sockets):how to implement persistent and pipeline supermyself Programming 0 06-09-2005 12:42 PM
sftp over a persistent connection (days/weeks) develops a memory leak da_kidd_er Linux - Software 1 12-22-2004 06:56 PM
Connection Refused http://localhost:631/ mlsbraves Linux - General 12 11-30-2004 05:57 PM
How to keep a persistent ssh (konsole) connection? coolersites Linux - Software 4 11-10-2003 03:00 PM
http connection problems on RedHat 7.3 Radicalm16 Linux - Networking 13 01-21-2003 10:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration