/faye_example

Example how to run faye

Primary LanguageRuby

Welcome to Rails

how create this project from scrash

setup

  1. rails 3.2.17 new project_name

  2. add gem ‘thin’ , gem ‘faye’ to Gemfile

  3. bundle install

  4. add websocket library

edit views/layouts/accplication.html.erb :
<%= javascript_include_tag 'http://localhost:9292/faye/client.js',  "application"  %>
  1. create socket on any page , see view/score/index.erb for example

  2. send data to subcriber ,see score_controller.rb

Run start Faye:

rackup faye.ru -s thin -E production -p 9292

Run start Web server

rails s

Run test

  1. goto localhost:3000/score

  2. run command: curl localhost:9292/faye -d ‘message={“channel”:“/messages/score”, “data”:“hello”}’

  3. run localhost:3000/score/broadcast/message to broadcast from server