我正在使用POCO C ++ lib版本1.4.3来实现HTTP服务器。在我的用例中,只有两个或三个客户端,我想拥有持久的连接。客户端发送带有放置请求的数据,服务器使用“ HTTP / 1.1 201 Created”(HTTP / 1.1 201已创建)进行应答。客户端打开多个连接。其中一个客户端可以同时打开20个连接。
我在HTTPServerParams和Poco :: Net :: ServerSocket(myPort)中使用默认值,并且在使用Poco :: ThreadPool(16,48)。
客户端发送一个http put请求,服务器将回答:
Server:
HTTP/1.1 201 Created
Connection: Close
Date: Thu, 31 Jan 2013 15:21:50 GMT
Run Code Online (Sandbox Code Playgroud)
我在带有WireShark的PCAP文件中看到了此结果。
如果我不希望服务器在放置请求后关闭连接,该怎么办?
---编辑并插入源代码:
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()<< …Run Code Online (Sandbox Code Playgroud)