Question

I am working on a project in C++, with POCO/NET. The Network code can be seen below:

URI uri("http://my.url.se" );
HTTPClientSession session(uri.getHost(), uri.getPort());

// prepare path
string path(uri.getPathAndQuery());
if (path. empty()) path = "/";

// send request
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
req.set("Accept", "AcceptString");
req.set("Consumer", "ALL");
req.set("Contract", "ALL");
session.sendRequest(req);

// recieve response

HTTPResponse res;
istream &is = session.receiveResponse(res); 

The application is working on both Android 2.3.6 (Samsung Galaxy Gio) and the latest Android version, but according to the following post (and developer.android):

https://stackoverflow.com/questions/15606791/android-httppost-freezes-and-crashes-app

a NetworkOnMainThreadException would be thrown on the newest Android version (Honeycomb or higher) if the Networking part would not be in a separate thread. I have not created a new thread, so my question is:

Can anyone confirm my assumption that it is implemented already/automatically uses a new thread in the Poco Net library?

Greatful for help!

Was it helpful?

Solution

Can anyone confirm my assumption that it is implemented already/automatically uses a new thread in the Poco Net library?

HTTPClientSession will not run on a separate thread, you will have to do that explicitly. You can use Poco:: Thread, Task or Activity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top