Overview
Download
Documentation
Community
Add-Ons & Services

HTTP KeepAlive with HTTPServer und HTTPClientSession

Please post support and help requests here.

HTTP KeepAlive with HTTPServer und HTTPClientSession

Postby Conan » 01 Jun 2010, 14:06

Hello!
I've got a problem with the http components and the http keepalive. Following all documentation I found the tcp session to the server should be kept connected if the http version is 1.1 and keepalive is set to true. My approach is the following:
Server side:

// Initialize HTTP-Server
ServerSocket svs(CGlobals::HTTP_Port);
HTTPServerParams* params = new HTTPServerParams();
params->setKeepAlive(true);
Poco::Timespan spanKeepAlive(30, 0);
params->setKeepAliveTimeout(spanKeepAlive);
params->setMaxKeepAliveRequests(1000000);
m_HTTPServer = new HTTPServer(new CRequestHandlerFactory(this), *m_HTTPPool, svs, params);

Client side

// Initialize HTTP client
SocketAddress addr(CGlobals::SkeletonAddr); // default address
m_client = new HTTPClientSession(addr);
m_client->setKeepAlive(true);
Poco::Timespan spanKeepAlive(30, 0);
m_client->setKeepAliveTimeout(spanKeepAlive);

Performin the Request:
// Prepare Request
HTTPRequest* request = new HTTPRequest("POST", "ktsod", "1.1");
request->setContentType("text/json; charset=ISO-8859-1");
request->setKeepAlive(true);
ostream& outStream = m_client->sendRequest(*request);

And in the request handler:

response.setVersion("1.1");
response.setKeepAlive(true);

However, an inspection of network traffic shows that a new tcp connection is established for every request (with the same HTTPClientSession of course)
So, how can I make HTTPKeepAlive work?

brgds
Sven Weiberg
Conan
 
Posts: 4
Joined: 01 Jun 2010, 11:49

Re: HTTP KeepAlive with HTTPServer und HTTPClientSession

Postby guenter » 01 Jun 2010, 22:17

You're specifying a bad value for HTTP version. The value should be "HTTP/1.1" - just use the Poco::Net::HTTPMessage::HTTP_1_1 constant.
Apart from that it's not necessary to explicitely call setKeepAlive() on the request object. The session will do that automatically.
guenter
 
Posts: 550
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HTTP KeepAlive with HTTPServer und HTTPClientSession

Postby Conan » 07 Jun 2010, 14:46

Hello Guenter!
Sorry, but this does not work. I specified the correct protocoll version everywhere I could. I even set keepAlive to true for every request and response. But a new connection is established for every roundtrip. Following MS Network Monitor every response from server to client has got a "Connection: Close" Entry.

Does there exist any working example of Http KeepAlive with Poco?

brgds
Sven
Conan
 
Posts: 4
Joined: 01 Jun 2010, 11:49

Re: HTTP KeepAlive with HTTPServer und HTTPClientSession

Postby guenter » 07 Jun 2010, 15:02

Maybe your server is configured to not allow persistent connections?
guenter
 
Posts: 550
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HTTP KeepAlive with HTTPServer und HTTPClientSession

Postby Conan » 07 Jun 2010, 16:48

Well, the server is Poco::HTTPServer (as can be seen in the first pos).
How do I configure him (not) to allow persistent connections?

brgds
Sven
Conan
 
Posts: 4
Joined: 01 Jun 2010, 11:49

Re: HTTP KeepAlive with HTTPServer und HTTPClientSession

Postby guenter » 10 Jun 2010, 12:44

The problem is probably in your server's request handler. You have to either specify a content length, or use chunked transfer encoding, otherwise the server will close the connection after each response (according to the HTTP specification). Same applied to the client, by the way.
guenter
 
Posts: 550
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HTTP KeepAlive with HTTPServer und HTTPClientSession

Postby Conan » 30 Jul 2010, 14:20

This does not solve the problem. If I use chunked transfer encoding, the server is sending the "Connection: Close" now. Still no HTTPKeepalive.
Conan
 
Posts: 4
Joined: 01 Jun 2010, 11:49


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron