[英]Websockets with Rails(Puma) - Error during WebSocket handshake: Unexpected response code: 200
I am trying to use websocket in my Rails4.1 application 我正在尝试在Rails4.1应用程序中使用websocket
Here are some relevant code snippets: 以下是一些相关的代码段:
Gemfile: 宝石文件:
gem 'websocket-rails'
gem 'puma'
development.rb 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: 在Chrome控制台中,我看到一个连接错误:
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? 有人可以帮我在Rails本地使用Web套接字所需做的事情吗?
Update1 更新1
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 我尝试在Unicorn服务器上运行时 ,按照Websockets在我的Rails应用程序中无法运行的方式添加以下内容,但可在Thin服务器上运行,但没有帮助
initializers/eventmachine.rb 初始值设定项/eventmachine.rb
Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive
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 您可以在config / events.rb文件中配置其余的操作,以及用于处理事件的控制器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.