A. Gille A. Gille - 1 month ago 13
C++ Question

Poco::Net::NoMessageException raised few seconds after HTTP/GET

Duplicate from POCO GitHub issue

I'm building a simple web server using Poco with Visual Studio 2015 on Windows 10.

A Poco::Net::NoMessageException is raised few seconds (approx. 15 secs) after connecting to this server with a web browser. It will happen again after refreshing the page; its doing this after each connection.

I didn't find anything in documentation, forum, stackoverflow. It would be very helpful to have a description in documentation of how/when/why these exceptions coming from deep inside the library are raised.

I also tried (just for fun) a

std::cout << req.getURI() << std::endl;
in
handleRequest(...)
and got a Memory Access Violation at address 0x00000000 with no other code in function.

Here is my code.
Preprocessor statements are omitted.

MyApp.c

int main(int argc, char ** argv)
{
myHTTPServer server;
return server.run(argc, argv);
}


myHTTPRequestHandlerFactory

// Header
class myHTTPRequestHandlerFactory : public HTTPRequestHandlerFactory
{
public:
virtual HTTPRequestHandler* createRequestHandler(const HTTPServerRequest&);
};

// Code
HTTPRequestHandler* myHTTPRequestHandlerFactory::createRequestHandler(const HTTPServerRequest& handler) {
return new myHTTPRequestHandler;
}


myHTTPRequestHandler

// Header
class myHTTPRequestHandler : public HTTPRequestHandler
{
public:
virtual void handleRequest(HTTPServerRequest &, HTTPServerResponse &);
};

// Code
void myHTTPRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response) {
response.setStatus(HTTPResponse::HTTP_OK);
//response.setContentLength(1024);
//response.setChunkedTransferEncoding(true);
std::ostream& out = response.send();
out << "<html><head></head><body>POCO POCO POCO</body></html>";
out.flush();
}


myHTTPServer

// Header
class myHTTPServer : public ServerApplication
{
protected:
int main(const std::vector<std::string>& v) {
HTTPServer server(new myHTTPRequestHandlerFactory, ServerSocket(80), new HTTPServerParams);

server.start();

std::cout << "Server started" << std::endl;

waitForTerminationRequest();

std::cout << "Server stopped" << std::endl;

server.stop();

return Application::EXIT_OK;
}
};

// No code in .c file


Thanks for helping me out

Answer

According to this answer, it's a normal POCO behaviour to raise Poco::Net::NoMessageException exceptions for no exceptional reason and you should safely ignore them.

For the Memory Access Violation, it's normal as it's not allowed to call std::cout in HTTPRequestHandler::handleRequest(...).

Comments