Project

General

Profile

Best way to send data from a session to another ?

Added by Sébastien Cache-Delanos over 9 years ago

Hi,

I'm pretty new to Wt and C. I'm currently developping a Web Application that needs to share data between different sessions. I have a textArea in a tab and on a button click I open a new window that receives data via Sockets in it's own textArea every 500ms. The goal is to get the content of the textArea that receives data and to put it in the other window's textArea.

What is the best way to do that ? The problem is that every new window is a new independent session...

Thanks,

Rgds.

(and sorry for my bad English)


Replies (4)

RE: Best way to send data from a session to another ? - Added by Wim Dumon over 9 years ago

Hello,

This can be done with Wt's server push functionality. While it's a bit complex to be called a simple example, the chat example in Wt should provide you with a lot of inspiration on how your application can be made in Wt.

Best regards,

Wim.

RE: Best way to send data from a session to another ? - Added by Sébastien Cache-Delanos over 9 years ago

Hi,

Yes it looks like I should use server push but it requires a pointer if I use it like this :

WServer::instance()->post(sessionID_, boost::bind(&APP::getPortData, APPPtr_, server->getData())); //send data to overview

I can send data like session id to a window via url but what about the pointer ?

Am I doing it wrong ?

RE: Best way to send data from a session to another ? - Added by Wim Dumon over 9 years ago

Watch out with sending session id's in URLs that you pass to others: it's a session secret, so sharing it is a security breach. Usually we register all sessions in a global vector from the application constructor and remove it at session destruction, so that there is a list of active sessions. Add some other number in that global store to identify parties, but I think it's very wise to make it different from the session ID.

Working in this way also give you the possibility to store the WApplication pointer too when you register the session ID. Problem solved :)

Alternatively, you could post to a (static) function that uses WApplication::instance() to retrieve the pointer to the application object:

class MyApp: public WApplication
{
public:
  static void getPortData(MyData *data);
private:
  void handleGetPortData(MyData *data);
};

void MyApp::getPortData(MyData *data)
{
  // thread local storage is used to ensure that WApplication::instance() will point to the correct WApplication object
  dynamic_cast<MyApp *>(WApplication::instance())->handleGetPortData(data);
}

RE: Best way to send data from a session to another ? - Added by Sébastien Cache-Delanos over 9 years ago

Hi there,

I finnaly did it. Thanks again for your help. I'm such a beginner in c that it was quite a challenge for me...

I now have a Global vector that stores everything I need in a structure.

Bye !

    (1-4/4)