HTTPサーバーを実装するためにPOCOC++libバージョン1.4.3を使用しています。私のユースケースでは、クライアントは2つか3つしかないので、持続的接続が必要です。クライアントはputリクエストでデータを送信し、サーバーは「HTTP /1.1201Created」で応答します。クライアントは複数の接続を開きます。クライアントの1つは、同時に20の接続を開くことができます。
HTTPServerParamsとPoco::Net :: ServerSocket(myPort)のデフォルトを使用し、Poco :: ThreadPool(16,48)を使用しています。
クライアントはhttpputリクエストを送信し、サーバーは次のように応答します。
Server:
HTTP/1.1 201 Created
Connection: Close
Date: Thu, 31 Jan 2013 15:21:50 GMT
この結果は、WireSharkを使用したPCAPファイルで確認できました。
putリクエスト後にサーバーが接続を閉じたくない場合はどうすればよいですか?
---ソースコードを編集して挿入します:
HTTPServer::HTTPServer(uint16_t port,
Poco::Net::HTTPRequestHandlerFactory* handlerFactory):
m_port(port),
m_wasStarted(false)
{
// HTTPServer takes ownership
Poco::Net::HTTPServerParams* options = new Poco::Net::HTTPServerParams;
try
{
m_threadPool.reset(new Poco::ThreadPool (16,48));
std::cout << "HTTPServerParams.keepAlive: "
<< options->getKeepAlive() << std::endl;
std::cout << "HTTPServerParams.keepAliveTimeout: "
<< options->getKeepAliveTimeout().totalSeconds() << std::endl;
std::cout << "HTTPServerParams.MaxKeepAliveRequests: "
<< options->getMaxKeepAliveRequests()<< std::endl;
std::cout << "HTTPServerParams.Timeout: "
<< options->getTimeout().totalSeconds() << std::endl;
m_server.reset(new Poco::Net::HTTPServer(handlerFactory,
*m_threadPool,
Poco::Net::ServerSocket(m_port),
options)
);
}
catch (const Poco::Exception& e)
{
//some code ...
}
}
クラスHTTPServerのプライベートメンバー:
uint16_t m_port;
bool m_wasStarted;
std::auto_ptr<Poco::ThreadPool> m_threadPool;
std::auto_ptr<Poco::Net::HTTPServer> m_server;