[英]websocket-rails, websocket handshake error
I followed the docs on the websocket-rails github wiki page, but couldn't overcome this difficulty, I get this error with chrome: 我遵循了websocket-rails github wiki页面上的文档,但是无法克服这个困难,我遇到了chrome这个错误:
WebSocket connection to 'ws://0.0.0.0:3000/websocket' failed: Error during WebSocket handshake: Unexpected response code: 301
I installed the websocket-rails
gem, generated the install, I set successfully config.middleware.delete Rack::Lock
in development.rb
; 我安装了
websocket-rails
gem,生成了安装程序,并成功将config.middleware.delete Rack::Lock
在development.rb
; I'm using Rails 4. 我正在使用Rails 4。
I got in the view: 我认为:
<script type="text/javascript">
var dispatcher = new WebSocketRails('0.0.0.0:3000/websocket');
</script>
I got in my chat_controller.rb
: 我进入了
chat_controller.rb
:
class ChatController < WebsocketRails::BaseController
def initialize_session
puts "Session Initialized"
end
def user_connected
puts 'user connected'
end
end
in my events.rb
: 在我的
events.rb
:
WebsocketRails::EventMap.describe do
subscribe :client_connected, :to => ChatController, :with_method => :user_connected
end
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). 在两者之间,我使用
bundle exec thin start
运行服务器,但是却出现了javascript错误(websocket连接失败错误301)。
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. 感谢Websocket Rails IRC的成员,我发现在我的路线中,我将语言环境附加在每条路径之前,因此找不到它。
Check your routes.rb
if someone hit that issue too ! 如果有人也遇到该问题,请检查您的
routes.rb
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.