Project

General

Profile

Get JSON data from other server while no user is visiting the webpage

Added by Franz Winter over 10 years ago

Hi

I wanna get JSON data from an other server. To get the JSON data I used Wt::Http::Client(app~~root()); This works when the user visits the homepage and a new WApplication gets created. But I like to get the JSON data periodically from the server. For this I implemented a thread which periodically calls the Wt::Http::Client(app~~>root());. But this doesn't work and I also understand why. Because the seassion was cloesed and the WApplication was destroyed. But now I don't know how to implement the behaviour that a thread can request JSON data from an other server while nobody visits the webpage.

Thanks

Frank


Replies (2)

RE: Get JSON data from other server while no user is visiting the webpage - Added by Wim Dumon over 10 years ago

Hi Frank,

I believe you can do this if you use this constructor of the Client classe:

  Client (WIOService &ioService, WObject *parent=0)

Your WServer object has a WIOService, and since WServer is a singleton, you can always refer to it, even without session.

You can leave parent 0, it is only used for memory management (child is deleted when parent is deleted). If parent is null, you'll need to delete your client class manually.

Best regards,

Wim.

RE: Get JSON data from other server while no user is visiting the webpage - Added by Franz Winter over 10 years ago

Thank you very much for the info. Now it works.

    (1-2/2)