Victor Ferreira
Victor Ferreira

Reputation: 6449

Websocket Rails getting 404 during handshake

I installed the 'websocket-rails' gem and after doing the default configuration I just created a JS dispatcher and I get a 404 error on chrome console.

This is my JS:

var dispatcher = new WebSocketRails('localhost:3000/websocket');

This is the message I get:

WebSocket connection to 'ws://localhost:3000/websocket' failed: Error during WebSocket handshake: Unexpected response code: 404

Everything else is as suggested by the first-steps-guide

events.rb

subscribe :test, :to => ChatServerController, :with_method => :test

controller/chat_server_controller.rb

class ChatServerController < WebsocketRails::BaseController
  def initialize_session
    # perform application setup here
    controller_store[:message_count] = 0
  end

  def test
      puts 'Hello'
  end
end

Upvotes: 1

Views: 600

Answers (1)

Cleverlemming
Cleverlemming

Reputation: 1370

There's one potential solution involving a gem dependency posted on github. But, if you look at the repo (151 open issues, 27 pull requests), it doesn't look like this gem is being actively maintained. The closed issues in 2016 are being closed by the same people who opened them.

You can probably make your application work by forcing websockets to use http by including a second parameter, set to false.

var Dispatcher = new WebSocketRails('localhost:3000/websocket', false);

I have concerns about how scalable using http polling will be and about the future of the websocket-rails gem. For me, it seems like the best way forward is to upgrade to Rails 5 and use Action Cable.

Upvotes: 1

Related Questions