Websocket-Rails gem running as standalone timesout

2019-09-16 17:30发布

问题:

I'm setting up this app that contains a chat module and everything is working fine on localhost.

Now I am trying to connect to the server as a standalone service, but the connection state in the dispatcher is always 'connecting' until it finally times out with the following message:

WebSocket connection to 'ws://myserver:3001/websocket' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

Gemfile

gem 'faye-websocket', '0.10.0'
gem 'websocket-rails', github: 'moaa/websocket-rails', branch: 'threadsocket-rails'
gem 'websocket-rails-js', github: 'websocket-rails/websocket-rails-js', branch: 'sub_protocols'
gem 'puma', group: [:development, :test, :production]

Javascript

var dispatcher = new WebSocketRails(WEBSOCKET_URL);

dispatcher.on_open = function(data) {
    console.log('Connection has been established: ', data);
};

Initializer

WebsocketRails.setup do |config|
    config.log_level = :debug
    config.log_path = "#{Rails.root}/log/websocket_rails.log"
    config.log_internal_events = false
    config.standalone = true
    config.synchronize = false
end

And I am starting the service as explained here: https://github.com/websocket-rails/websocket-rails/issues/302

If I change the URL/Port in the dispatcher, i get different errors. but the one that should work takes like 2 or 3 minutes and then times out.

Have you got any ideas on what could be happening? Is there any special configuration I must set?