I have been using Sinatra for sometime now and I would like to add some realtime features to my web-app by pushing the data via websockets.
I have successfully used the gem 'em-websocket' on its own, but have not been able to write one ruby file that has a sinatra web server AND a web-socket server.
I've tried spinning the run! or start! methods off in separate threads with no success.
Has anyone gotten this to work?
I want to have them in the same file as I can then share variables between the two servers.
Thanks!
Did not try it, but should not be too hard:
Also, Cramp has a websocket implementation that works directly with Thin/Rainbows! you might be able to extract, so you won't even need to run the server on another port.
I stumbled onto this websocket-rack github project which is basically a rackified em-websocket and actually got it to work nicely side-by-side with a Sinatra app. Here's my config.ru:
Have fun!
Colin
Thanks Konstantin... that worked! I had to tweak your code slightly. I added comments where I changed it.
-poul
I've been using sinatra-websocket. It let's you run the websocket server in the same process and on the same port as Sinatra.
Disclaimer: I'm the maintainer.
FYI, you can also use Padrino apps with EventMachine (as they are subsets of Sinatra apps):
Cheers, Mike