Skip to content

Commit

Permalink
add single process ping-pong example
Browse files Browse the repository at this point in the history
  • Loading branch information
sprsquish committed May 14, 2009
1 parent 41b4e6f commit 7e86bdf
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/ping_pong.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'blather/client/dsl'
$stdout.sync = true

module Ping
extend Blather::DSL
def self.run; client.run; end

setup 'echo@jabber.local/ping', 'echo'

status :from => Blather::JID.new('echo@jabber.local/pong') do |s|
puts "serve!"
say s.from, 'ping'
end

message :chat?, :body => 'pong' do |m|
puts "ping!"
say m.from, 'ping'
end
end

module Pong
extend Blather::DSL
def self.run; client.run; end

setup 'echo@jabber.local/pong', 'echo'
message :chat?, :body => 'ping' do |m|
puts "pong!"
say m.from, 'pong'
end
end

trap(:INT) { EM.stop }
trap(:TERM) { EM.stop }
EM.run do
Ping.run
Pong.run
end

0 comments on commit 7e86bdf

Please sign in to comment.