Websockets with Rails (Puma) - WebSocket handshake error: Unexpected response code: 200

I am trying to use websocket in my Rails4.1 application

Here are some relevant code snippets:

Gemfile:

gem 'websocket-rails' gem 'puma' 

development.rb

  config.middleware.delete Rack::Lock 

I start the server locally as:

 bundle exec puma -p 3000 

In the chrome console, I see a connection error:

 new WebSocketRails('localhost:3000/post/hello', true); WebSocket connection to 'ws://localhost:3000/post/hello' failed: Error during WebSocket handshake: Unexpected response code: 200 

Can someone help with what I need to do to use network sockets locally in Rails?


Update1

I tried to add the following data according to websites that do not work in my Rails application when I start the Unicorn server but work on a thin server , but that did not help

Initializers / eventmachine.rb

 Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive 
0
source share
1 answer

Try this in the console:

 window.dispatcher = new WebSocketRails window.document.location.host + '/websocket' 

Configuring the rest of what you want to do in the config / events.rb file and any controllers that you use to handle events

+1
source

Source: https://habr.com/ru/post/974804/


All Articles