-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_send_data_xmpp
executable file
·72 lines (61 loc) · 1.6 KB
/
run_send_data_xmpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env ruby
require 'rubygems'
require File.dirname(__FILE__) + '/lib/pelvis'
require File.dirname(__FILE__) + '/lib/pelvis/protocols/xmpp'
require File.dirname(__FILE__) + '/examples/actors/herault'
require File.dirname(__FILE__) + '/examples/actors/echo'
def connect_herault
Pelvis.connect(:xmpp, :jid => 'herault@localhost/agent', :password => 'testing', :advertise => false) do |agent|
agent.add_actor Herault
agent.on_advertised do
puts "herault is ready"
connect_echo
end
end
end
def connect_echo
Pelvis.connect(:xmpp, :jid => 'dummy@localhost/agent', :password => 'testing') do |agent|
agent.add_actor Echo
agent.on_advertised do
puts "echo is ready"
connect_console
end
end
end
def connect_console
Pelvis.connect(:xmpp, :jid => 'admin@localhost/agent', :password => 'testing') do |agent|
agent.on_advertised do
puts "console is ready"
r = agent.request(:all, "/do/echo", {}, :identities => ["dummy@localhost/agent"])
r.on_received do |data|
puts data[:output]
end
r.on_completed do |event|
puts event
EM::stop_event_loop
end
prompt_for_data do |data|
puts "SENDING: #{data}"
r.put :input => data
end
end
end
end
def prompt_for_data(&block)
op = proc { $stdin.gets.chomp }
cb = proc {|data|
if "LQUIT" === data.chomp.upcase
EM::stop_event_loop
else
block.call(data) unless block.nil?
EM::defer(op, cb)
end
}
EM::defer(op, cb)
end
if ENV["DEBUGGER"]
Pelvis.logger.level = Logger::DEBUG
end
EM.run do
connect_herault
end