I've tried using eventmachine b开发者_开发问答ut all I have is an application running sinatra on one side and an event machine server on the other. I can't figure out how to run a sinatra application as a websocket.
For example, I want to serve this as a websocket:
get '/' do #pull info from DB and display end
Any help is appreciated.
Thanks! L.
Did you check "sinatra-websocket" ?
From the maintainer:
[...] It let's you run the websocket server in the same process and on the same port as Sinatra. [...]
From what I understand doing this would require writing an extension or possibly modifying Sinatra it's self to use web-sockets instead of http.
I would write an extension that routes the request through a EM websocket server running in side the extension if I use ws.get
or ws.post
insted if just get
or post
I've been down this road but it is not something I would recommend. It is possible to have the same Rack stack handling both Sinatra and Websocket somehow, using Thin, but there are more problems than benefits. If you want to see how I did it, look at:
https://github.com/HakubJozak/mana/blob/before-sinatra-removal/config.ru
Now I am actually porting the app to use Rails 3.1 for "static" pages and brain simple quick backend based on github.com/igrigorik/em-websocket.
精彩评论