websocket-rails,websocket 握手错误 [英] websocket-rails, websocket handshake error
问题描述
我遵循了 websocket-rails github wiki 页面上的文档,但无法克服这个困难,我在使用 chrome 时遇到此错误:
I followed the docs on the websocket-rails github wiki page, but couldn't overcome this difficulty, I get this error with chrome:
WebSocket connection to 'ws://0.0.0.0:3000/websocket' failed: Error during WebSocket handshake: Unexpected response code: 301
我安装了 websocket-rails
gem,生成安装,我在 development.rb
中成功设置了 config.middleware.delete Rack::Lock
代码>;我使用的是 Rails 4.
I installed the websocket-rails
gem, generated the install, I set successfully config.middleware.delete Rack::Lock
in development.rb
; I'm using Rails 4.
我进入了视图:
<script type="text/javascript">
var dispatcher = new WebSocketRails('0.0.0.0:3000/websocket');
</script>
我进入了我的chat_controller.rb
:
class ChatController < WebsocketRails::BaseController
def initialize_session
puts "Session Initialized"
end
def user_connected
puts 'user connected'
end
end
在我的 events.rb
中:
WebsocketRails::EventMap.describe do
subscribe :client_connected, :to => ChatController, :with_method => :user_connected
end
如您所见,我的目标是每次有人访问页面时在我的瘦服务器控制台中显示会话已初始化"和用户已连接".在此期间,我使用 bundle exec Thin start
运行服务器,但出现了 javascript 错误(websocket 连接失败错误 301).
As you can see, my goal is to display "Session Initialized", and "user connected", in my thin server console each time that someone goes on a page. Between, I run the server with bundle exec thin start
, but I got a javascript error instead (websocket connection failed error 301).
推荐答案
感谢 Websocket Rails IRC 的成员,我发现在我的路由中,我在每条路径之前附加了语言环境,所以它找不到
Thanks to the members of the Websocket Rails IRC, I found out that in my route, I was appending the locale before every path, so it coudln't find it.
检查你的 routes.rb
是否有人也遇到了这个问题!
Check your routes.rb
if someone hit that issue too !
这篇关于websocket-rails,websocket 握手错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!