【问题标题】:Websockets with Rails(Puma) - Error during WebSocket handshake: Unexpected response code: 200带有 Rails(Puma)的 Websockets - WebSocket 握手期间出错:意外的响应代码:200
【发布时间】:2015-08-15 22:36:12
【问题描述】:

我正在尝试在我的 Rails4.1 应用程序中使用 websocket

这里有一些相关的代码sn-ps:

宝石文件:

gem 'websocket-rails'
gem 'puma'

开发.rb

 config.middleware.delete Rack::Lock

我在本地启动服务器:

bundle exec puma -p 3000

在 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

谁能帮助我在 Rails 中本地使用 Web 套接字需要做些什么?


更新1

我尝试按照Websockets not working in my Rails app when I run on Unicorn server, but works on a Thin server 添加以下内容,但没有帮助

初始化程序/eventmachine.rb

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

【问题讨论】:

  • 投反对票的原因?
  • 不是我的反对意见,但我建议不要删除“Rack::Lock”,除非你知道自己在做什么。

标签: ruby-on-rails websocket ruby-on-rails-4.1 puma websocket-rails


【解决方案1】:

在您的控制台中试试这个:

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

您可以在 config/events.rb 文件中配置您想要执行的其余操作,以及用于处理事件的任何控制器

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-09
  • 2019-04-28
  • 2020-01-15
  • 1970-01-01
  • 2014-05-15
  • 2017-08-21
相关资源
最近更新 更多