rafzi / WAMP_POCO

WAMP for C++ 11 on POCO
Apache License 2.0
20 stars 5 forks source link

question regarding registering a remoted procedure #6

Closed xgdgsc closed 7 years ago

xgdgsc commented 7 years ago

I tried with the example in readme of "Registering a remoted Procedure" , it registers fine showing "Registered with ID ..." on linux (on windows it doesn' t show this register success) . But when I call this square function from an external javascript, it shows wamp.error.no_such_procedure. I' ve called the thread to sleep for some time before the program exits using std::this_thread::sleep_for(std::chrono::seconds(10));. What should I do to make this work?

rafzi commented 7 years ago

Can't really help you with just this information. What do the router logs say?

xgdgsc commented 7 years ago
 wamp:session incoming message [64,2,{},"com.myapp.square"] for sessionID: 1663417689599482 +1ms
  wamp:router switching: 64, REGISTER +0ms
  wamp:procedure getting com.myapp.square:  +0ms
  wamp:procedure registering procedure com.myapp.square +0ms
  wamp:procedure procedure id: 6706405965372796 +0ms
  wamp:procedure session id: 1663417689599482 +0ms
  wamp:session outgoing message: [65,2,6706405965372796] +0ms
  wamp:session incoming message [48,8582995522796246,{},"com.myapp.square",[6]] for sessionID: 5399966374875578 +611ms                                                                                                                  
  wamp:router switching: 48, CALL +0ms
  wamp:procedure getting com.myapp.square:  +0ms
  wamp:session-manager getting session for id: 1663417689599482 +0ms
  wamp:transactions setting transaction with ID: 8582995522796246 for sessionID: 5399966374875578 +0ms
  wamp:session outgoing message: [68,8582995522796246,6706405965372796,{},[6],null] +0ms
  wamp:session closing session for ID: 1663417689599482 and IP: 127.0.0.1 +4ms
  wamp:session cleaning... +0ms
  wamp:procedure removing com.myapp.square:  +0ms
  wamp:session-manager removing session: 1663417689599482 for realm: com.example.inge +0ms
  wamp:session incoming message [48,7508813658939318,{},"com.myapp.square",[6]] for sessionID: 5399966374875578 +2s
  wamp:router switching: 48, CALL +0ms
  wamp:procedure getting com.myapp.square:  +0ms
  wamp:session outgoing message: [8,48,7508813658939318,{},"wamp.error.no_such_procedure",null] +1ms
  wamp:session incoming message [48,3654086541748448,{},"com.myapp.square",[6]] for sessionID: 5399966374875578 +2s
  wamp:router switching: 48, CALL +1ms
  wamp:procedure getting com.myapp.square:  +0ms
  wamp:session outgoing message: [8,48,3654086541748448,{},"wamp.error.no_such_procedure",null] +0ms
  wamp:session incoming message [48,981410507874554,{},"com.myapp.square",[6]] for sessionID: 5399966374875578 +2s
  wamp:router switching: 48, CALL +0ms
  wamp:procedure getting com.myapp.square:  +0ms
  wamp:session outgoing message: [8,48,981410507874554,{},"wamp.error.no_such_procedure",null] +0ms
  wamp:session incoming message [48,2886536384619308,{},"com.myapp.square",[6]] for sessionID: 5399966374875578 +2s
  wamp:router switching: 48, CALL +1ms
  wamp:procedure getting com.myapp.square:  +0ms
  wamp:session outgoing message: [8,48,2886536384619308,{},"wamp.error.no_such_procedure",null] +0ms

This is the router log. Seems the register is successful and gets removed after a call.

rafzi commented 7 years ago

Seems like the session of the peer that registered the procedure is closed. To be clear: If the autobahn::session is destroyed, the connection is closed and the router will remove the registrations.

Are you sure the session object is kept alive? There could also be an error that causes the session to be closed.

Have you registered a poco logger to receive client side errors? see https://github.com/rafzi/WAMP_POCO/blob/master/examples_poco/crossbar_authenticate/main.cpp

xgdgsc commented 7 years ago

the code is like this:

session ws;
auto r1 = then(ws.provide("com.myapp.square",
                              [](const anyvec& args, const anymap& kwargs) {
                                cout << "Procedure is invoked .." << endl;
                                double x = args[0].convert<double>();
                                return x * x;
                              }),

                   [](future<registration> reg) {
                     cout << "Registered with ID " << reg.get().id << endl;
                   });
    std::this_thread::sleep_for(std::chrono::seconds(10));
    ws.stop(eptr);

I believe the session object should be alive for 10 seconds.(I also tried std::cin.ignore()) From the log it seems the wamp router tries to reach out for this cpp procedure when it gets called by another js script and then closes the session with cpp. The procedure of square never gets called.

xgdgsc commented 7 years ago

I found it may be related to the router, the problem might be with the https://github.com/ivaylopivanov/wamp-server router. The crossbar router works fine.