-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathclient.rb
executable file
·101 lines (87 loc) · 2.26 KB
/
client.rb
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env ruby
# Copyright (c) ZeroC, Inc.
require 'Ice'
require 'thread'
require 'timeout'
Ice::loadSlice('Session.ice')
def run(communicator, args)
if args.length > 0
puts $0 + ": too many arguments"
return 1
end
while true
print "Please enter your name ==> "
STDOUT.flush
name = STDIN.readline.chomp
if name.length > 0
break
end
end
base = communicator.propertyToProxy('SessionFactory.Proxy')
factory = Demo::SessionFactoryPrx::checkedCast(base)
if not factory
puts $0 + ": invalid proxy"
return 1
end
session = factory.create(name)
hellos = []
menu()
destroy = true
shutdown = false
while true
begin
print "==> "
STDOUT.flush
c = STDIN.readline.chomp
if c =~ /^[0-9]+$/
index = c.to_i
if index < hellos.length
hello = hellos[index]
hello.sayHello()
else
puts "Index is too high. " + hellos.length.to_s + " hello objects exist so far.\n" +\
"Use `c' to create a new hello object."
end
elsif c == 'c'
hellos.push(session.createHello())
puts "Created hello object " + (hellos.length - 1).to_s
elsif c == 's'
destroy = false
shutdown = true
break
elsif c == 'x'
break
elsif c == 't'
destroy = false
break
elsif c == '?'
menu()
else
puts "unknown command `" + c + "'"
menu()
end
rescue EOFError
break
end
end
if destroy
session.destroy
end
if shutdown
factory.shutdown()
end
return 0
end
def menu
print <<MENU
usage:
c: create a new per-client hello object
0-9: send a greeting to a hello object
s: shutdown the server and exit
x: exit
t: exit without destroying the session
?: help
MENU
end
status = Ice::initialize(ARGV, "config.client") { |communicator, args| run(communicator, args) }
exit(status)