Take the 2-minute tour ×

I've tried using eventmachine but 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

Any help is appreciated.

Thanks! L.

share|improve this question
add comment

3 Answers

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. [...]

share|improve this answer
add comment

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

share|improve this answer
add comment

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:


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.

share|improve this answer
add comment

Your Answer


