简体   繁体   English

带Rails(Puma)的Websockets-WebSocket握手期间出错:意外的响应代码:200

[英]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.

相关问题 WebSocket 握手期间的 Rails 5 错误:意外响应代码:502 - Rails 5 Error during WebSocket handshake: Unexpected response code: 502 Websocket导轨(Faye-websocket)握手错误代码200-AWS ElasticBeanstalk,nginx,puma - Websocket rails (Faye-websocket) handshake error code 200 - AWS ElasticBeanstalk, nginx, puma Rails 5 Actioncable-失败:WebSocket握手期间出错:意外的响应代码:502 - Rails 5 Actioncable - failed: Error during WebSocket handshake: Unexpected response code: 502 ActionCable Rails 5(Passenger) - 失败:WebSocket握手期间出错:意外响应代码:404 - ActionCable Rails 5 (Passenger) - failed: Error during WebSocket handshake: Unexpected response code: 404 ActionCable - WebSocket 握手期间出错:意外响应代码:404 - ActionCable - Error during WebSocket handshake: Unexpected response code: 404 WebSocket握手期间出错:意外的响应代码:503 - Error during WebSocket handshake: Unexpected response code: 503 WebSocket握手期间出错:意外的响应代码:502 - Error during WebSocket handshake: Unexpected response code: 502 Actioncable Nginx和Puma WebSocket握手:意外响应 - Actioncable Nginx and Puma WebSocket handshake: Unexpected response 在websocket握手期间Rails ActionCable错误 - Rails ActionCable error during websocket handshake 在 WebSocket 握手期间 Rails 6 Production ActionCable 错误 - Rails 6 Production ActionCable Error during WebSocket handshake
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM