|Keep It Simple, Stupid|
PSGI, Plack, Twiggy, AnyEvent and SockJS... I need helpby xtpu2 (Acolyte)
|on Apr 08, 2014 at 20:48 UTC||Need Help??|
xtpu2 has asked for the
wisdom of the Perl Monks concerning the following question:
**UPDATE: The issue has been resolved. I've preserved the original post, but added the final, working code to the bottom. I sincerely hope this benefits others!**
I'm very new to event-based programming in Perl. I'm currently trying to get to grips with a Plack / Twiggy / AnyEvent / SockJS combination (details below). Unfortunately, I'm not doing so well.
I'm trying to write a program that will send the client a message whenever a certain event happens (in the production version, the event will be a database update, but for the purposes of this test, I'm trying to use an AnyEvent timer). However, I have no clue from which end to approach this. Here is the code I have so far (this is heavily based on the example code from the SockJS-perl docs):
This code is executed with:plackup --server Twiggy::TLS --port 5000 --tks-key /path/to/key --tls-cert /path/to/cert app.psgi
This code doesn't work! Console.log outputs the following:
It is obvious that $w->recv is the culprit because if I comment out that line, the server works and outputs 'got your message' when I send a message to it. However, in that case the timer doesn't work.
I know that SockJS is a module in very early development, and I have contacted the author for more information, but I have the feeling that my problem has nothing to do with SockJS, but with the way Plack, Twiggy and AnyEvent work. Hence my posting the question here on perlmonks. Any input / insight would be greatly appreciated (because not understanding this is driving me up the wall!!!)
**Update: The issue has been resolved!**
Final, working code: