RComet is an implementation of the Bayeux protocol in Ruby. Bayeux Protocol : svn.cometd.org/trunk/bayeux/bayeux.html
-
It was tested only with Dojo
-
Does not work with Thin :(
require 'rcomet/server' # We create a new RComer server server = RComet::Server.new( :host => '0.0.0.0', :port => 8990, :server => :mongrel, :mount => '/' ) { # We create a new channel (/graph) with a callback to manipulate recieved data channel['/graph'].callback do |message| # Someone have send data on channel /graph # We push the data message to the same channel # We don't need to do this... But it's an example channel['/graph'].data( message['data'] ) end } # Let's start the server server.start # Then we start for a infinity loop while true # We push new data to the channel /graph every 5 second server.channel['/graph'].data( [rand(10),rand(10),rand(10),rand(10),rand(10),rand(10),rand(10),rand(10)] ) sleep(5) end
require 'rcomet/client' # Initialisation x = RComet::Client.new( 'http://localhost:8990/' ) # Handshake x.handshake # Publication x.publish( '/login', "daemon" ); # Subscriptions x.subscribe( "/from/greg" ) { |r| puts "#{r["username"]} : #{r["message"]}" } x.subscribe( "/from/daemon" ) { |r| puts "#{r["username"]} : #{r["message"]}" } # Connection x.connect # Mainloop msg = "" while msg != "quit" msg = $stdin.readline.chomp unless msg == "quit" channel = "/from/daemon" data = { "username" => "daemon", "message" => msg } r = x.publish( channel, data ) unless r["successful"] puts "=> Message not send !" end end end x.disconnect
See examples…
-
json
-
rack
gem install rcomet
RComet is freely distributable according to the terms of the GNU General Public License.
This program is distributed without any warranty. See the file ‘LICENCE’ for details.