Javascript websocket轨道,websocket握手错误
我遵循了websocket rails github wiki页面上的文档,但无法克服这个困难,我在chrome上遇到了这个错误:Javascript websocket轨道,websocket握手错误,javascript,ruby-on-rails,websocket,ruby-on-rails-4,Javascript,Ruby On Rails,Websocket,Ruby On Rails 4,我遵循了websocket rails github wiki页面上的文档,但无法克服这个困难,我在chrome上遇到了这个错误: WebSocket connection to 'ws://0.0.0.0:3000/websocket' failed: Error during WebSocket handshake: Unexpected response code: 301 我安装了websocketrailsgem,生成了安装,我在development.rb中成功地设置了config
WebSocket connection to 'ws://0.0.0.0:3000/websocket' failed: Error during WebSocket handshake: Unexpected response code: 301
我安装了websocketrails
gem,生成了安装,我在development.rb中成功地设置了config.middleware.delete Rack::Lock
;我使用的是Rails 4
我看到:
<script type="text/javascript">
var dispatcher = new WebSocketRails('0.0.0.0:3000/websocket');
</script>
在myevents.rb
中:
class ChatController < WebsocketRails::BaseController
def initialize_session
puts "Session Initialized"
end
def user_connected
puts 'user connected'
end
end
WebsocketRails::EventMap.describe do
subscribe :client_connected, :to => ChatController, :with_method => :user_connected
end
如您所见,我的目标是在每次有人进入页面时,在瘦服务器控制台中显示“会话已初始化”和“用户已连接”。在这段时间内,我用bundle exec thin start运行服务器,但是我得到了一个javascript错误(websocket连接失败错误301)。多亏了websocket Rails IRC的成员,我发现在我的路径中,我在每个路径之前都附加了区域设置,所以它找不到它
如果有人也遇到了这个问题,请检查你的路线.rb
将routes.rb路由用于ws
协议吗?