-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.rb
More file actions
executable file
·162 lines (144 loc) · 4.64 KB
/
Client.rb
File metadata and controls
executable file
·162 lines (144 loc) · 4.64 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env ruby
# **********************************************************************
#
# Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
#
# **********************************************************************
require 'Ice'
Ice::loadSlice('Hello.ice')
def menu
print <<MENU
usage:
t: send greeting as twoway
o: send greeting as oneway
O: send greeting as batch oneway
d: send greeting as datagram
D: send greeting as batch datagram
f: flush all batch requests
T: set a timeout
P: set a server delay
S: switch secure mode on/off
s: shutdown server
x: exit
?: help
MENU
end
class Client < Ice::Application
def interruptCallback(sig)
begin
Ice::Application::communicator.destroy
rescue => ex
puts ex
end
exit(0)
end
def run(args)
if args.length > 0
puts $0 + ": too many argumnets"
return 1
end
#
# Since this is an interactive demo we want the custom interrupt
# callback to be called when the process is interrupted.
#
Ice::Application::callbackOnInterrupt
twoway = Demo::HelloPrx::checkedCast(
Ice::Application::communicator().stringToProxy('hello').ice_twoway().ice_secure(false))
if not twoway
puts $0 + ": invalid proxy"
return 1
end
oneway = twoway.ice_oneway()
batchOneway = twoway.ice_batchOneway()
datagram = twoway.ice_datagram()
batchDatagram = twoway.ice_batchDatagram()
secure = false
timeout = -1
delay = 0
menu()
c = nil
while c != 'x'
begin
print "==> "
STDOUT.flush
line = STDIN.readline
c = line[0..0]
if c == 't'
twoway.sayHello(delay)
elsif c == 'o'
oneway.sayHello(delay)
elsif c == 'O'
batchOneway.sayHello(delay)
elsif c == 'd'
if secure
puts "secure datagrams are not supported"
else
datagram.sayHello(delay)
end
elsif c == 'D'
if secure
puts "secure datagrams are not supported"
else
batchDatagram.sayHello(delay)
end
elsif c == 'f'
batchOneway.ice_flushBatchRequests()
batchDatagram.ice_flushBatchRequests()
elsif c == 'T'
if timeout == -1
timeout = 2000
else
timeout = -1
end
twoway = twoway.ice_invocationTimeout(timeout)
oneway = oneway.ice_invocationTimeout(timeout)
batchOneway = batchOneway.ice_invocationTimeout(timeout)
if timeout == -1
puts "timeout is now switched off"
else
puts "timeout is now set to 2000ms"
end
elsif c == 'P'
if delay == 0
delay = 2500
else
delay = 0
end
if delay == 0
puts "server delay is now deactivated"
else
puts "server delay is now set to 2500ms"
end
elsif c == 'S'
secure = !secure
twoway = twoway.ice_secure(secure)
oneway = oneway.ice_secure(secure)
batchOneway = batchOneway.ice_secure(secure)
datagram = datagram.ice_secure(secure)
batchDatagram = batchDatagram.ice_secure(secure)
if secure
puts "secure mode is now on"
else
puts "secure mode is now off"
end
elsif c == 's'
twoway.shutdown()
elsif c == 'x'
# Nothing to do
elsif c == '?'
menu()
else
puts "unknown command `" + c + "'"
menu()
end
rescue Ice::Exception => ex
puts ex
rescue EOFError
break
end
end
return 0
end
end
app = Client.new()
exit(app.main(ARGV, "config.client"))