UPDATE: It was strange to me that websocket-rails only supports EventMachine-based web servers, and the faye-websocket on which websocket-rails are based supports many multithreading web servers .
After further research and testing, I realized that my previous assumption was wrong. Instead of requiring an EventMachine-based web server, websocket-rails seems to require a multi-threaded (so there is no Unicorn) web server that supports rack.hijack . ( Puma meets these criteria, being comparable in performance to the Unicorn.)
Under this assumption, I tried to solve the EventMachine not initialized error using the most direct method, namely, initializing the EventMachine by inserting the following code into the config/initializers/eventmachine.rb :
Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
and .... success!
I managed to get Websocket Rails to work on my local server through a single port using a non- EventMachine-server without an offline server . (Rails 4.1.6 on Ruby 2.1.3p242)
This should be applicable to Heroku if you have no restrictions on choosing a web server.
A WARNING. This is not an officially supported configuration for websocket-rails. Care must be taken when using multi-threaded web servers such as Puma, as your code and its dependencies must be thread safe. A (temporary?) Workaround is to limit the maximum flows per worker to one and increase the number of workers, reaching a system like Unicorn.
Out of curiosity, I tried Unicorn again after fixing the above problem:
The first connection to the web server was received by the web server ( Started GET "/websocket" for ... ), but the state the websocket client was stuck on connecting , it seems to hang indefinitely.
The second connection resulted in an HTTP 500 app error: deadlock; recursive locking (ThreadError) with app error: deadlock; recursive locking (ThreadError) app error: deadlock; recursive locking (ThreadError) displayed in the server console output.
As a result of the (potentially dangerous) Rack::Lock removal action, a blocking error can be resolved, but the connections still freeze, although the server console indicates that the connections were accepted.
No wonder this fails. From the error message, I think Unicorn is incompatible due to reasons related to its network architecture (threading / concurrency). But then again, it might be some kind of mistake in this rack middleware ...
Does anyone know the specific technical reasons why Unicorn is incompatible?
ORIGINAL RESPONSE:
Have you checked the ports for both the web server and the WebSocket server and debug logs? These error messages sound as if they are connecting to something other than the WebSocket server.
A key difference in the two web servers you use seems to be that one (thin) is EventMachine and one (Unicorn) not. The Websocket Rails wiki indicates that one internal port (provided as an environment variable) is externally as port 80. A WebSocket server usually requires its own socket address (port number) (which can be processed by reverse proxying the WebSocket server). Websocket-Rails seems to manage this limitation by connecting to an existing EventMachine- based web server (which Unicorn does not provide) rack capture .