Standalone Server Mode

Amir Sharif edited this page Aug 5, 2015 · 5 revisions

WebsocketRails can now be started as a standalone server to support non-eventmachine based web servers such as Phusion Passenger or Unicorn. The standalone server requires an active Redis server to enable publishing channel events to the WebSocket server from anywhere in your application.

Enabling Standalone Server Mode

You can enable the standalone server mode through the configuration option in your websocket_rails.rb initializer file.

# At the top of config/initializers/websocket_rails.rb
WebsocketRails.setup do |config|
  config.standalone = true
end

If your redis server is not running on your localhost at the default port, override the redis options in your configuration as well.

WebsocketRails.setup do |config|
   config.standalone = true
   config.redis_options = {:host => 'your.host', :port => '6379'}
end

By default, the standalone server will listen on port 3001. Make sure you set the JavaScript client to connect to the correct port. You can override the default port in the configuration by setting the standalone_port option.

WebsocketRails.setup do |config|
  config.standalone = true
  config.standalone_port = 3245
end

The javascript dispatcher will need to connect to your.host:3001/websocket.

var dispatcher = new WebSocketRails('your.host:3001/websocket')

Starting and Stopping the Standalone Server

You can start the standalone server with the websocket_rails:start_server rake task.

rake websocket_rails:start_server

All log output will be written to log/websocket_rails.log. If you have your config.log_level set to :debug, you will find the output in that file.

To stop the server, use the accompanying websocket_rails:stop_server rake task.

rake websocket_rails:stop_server
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.