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

岁酱吖の 提交于 2019-12-12 03:38:57

问题


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 am starting 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 anyone help with what I need to do to use web sockets locally in Rails?


Update1

I tried adding following as per Websockets not working in my Rails app when I run on Unicorn server, but works on a Thin server but it did not help

initializers/eventmachine.rb

Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive

回答1:


Try this in your console:

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

You configure the rest of what you want to do in the config/events.rb file and whatever controllers you use to handle the events



来源:https://stackoverflow.com/questions/32030064/websockets-with-railspuma-error-during-websocket-handshake-unexpected-respo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!