I found this example of using faye for a chatroom type app as I am
trying to get a feel for push servers:
http://net.tutsplus.com/tutorials/ruby/how-to-use-faye-as-a-real-time-push-server-in-rails/
I got some of that to work, although multiuser from the same browser
doesn't exactly make sense.
I then tried to look into a server side client. I am using a windows
laptop for everything.
I have the following code below which publishes a message to the
chatroom fine, but it never really exits.
The last statement "puts 'end'" is never reached. If I put EM.stop or
an exit statement inside the event machine block, then the messages
don't make it to the chat room.
The other thin I noticed is if I have a loop that puts say 5 messages
to the chat room, but sleeps for several seconds between each. They
don't show up until they have all been published. It's like it needs
to reach the bottom of the block, but once there it never exits the
block.
require 'eventmachine'
require 'faye'
client = Faye::Client.new('http://localhost:9292/faye')
EM.run {
client.subscribe('/messages/public') do |message|
puts message.inspect
end
client.publish('/messages/public', 'username' => 'Joe',
'msg' => "hey there again")
}
puts 'end'
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment