summaryrefslogtreecommitdiff
path: root/py/demo/Ice/hello/Client.py
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2005-09-14 06:26:31 +0000
committerMatthew Newhook <matthew@zeroc.com>2005-09-14 06:26:31 +0000
commit502335f0e2d6d407b8c93690bd01d35c33e1f0cf (patch)
tree38f5b655a2a2411537b9361153d0b81f7f672325 /py/demo/Ice/hello/Client.py
parentBug 454. (diff)
downloadice-502335f0e2d6d407b8c93690bd01d35c33e1f0cf.tar.bz2
ice-502335f0e2d6d407b8c93690bd01d35c33e1f0cf.tar.xz
ice-502335f0e2d6d407b8c93690bd01d35c33e1f0cf.zip
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=335
Diffstat (limited to 'py/demo/Ice/hello/Client.py')
-rw-r--r--py/demo/Ice/hello/Client.py196
1 files changed, 91 insertions, 105 deletions
diff --git a/py/demo/Ice/hello/Client.py b/py/demo/Ice/hello/Client.py
index 42fca977c8c..dcd9412b071 100644
--- a/py/demo/Ice/hello/Client.py
+++ b/py/demo/Ice/hello/Client.py
@@ -13,6 +13,7 @@ import sys, traceback, Ice
Ice.loadSlice('Hello.ice')
import Demo
+
def menu():
print """
usage:
@@ -29,108 +30,93 @@ x: exit
?: help
"""
-def run(args, communicator):
- properties = communicator.getProperties()
- refProperty = 'Hello.Proxy'
- proxy = properties.getProperty(refProperty)
- if len(proxy) == 0:
- print args[0] + ": property `" + refProperty + "' not set"
- return False
-
- base = communicator.stringToProxy(proxy)
- twoway = Demo.HelloPrx.checkedCast(base.ice_twoway().ice_timeout(-1).ice_secure(False))
- if not twoway:
- print args[0] + ": invalid proxy"
- return False
-
- oneway = Demo.HelloPrx.uncheckedCast(twoway.ice_oneway())
- batchOneway = Demo.HelloPrx.uncheckedCast(twoway.ice_batchOneway())
- datagram = Demo.HelloPrx.uncheckedCast(twoway.ice_datagram())
- batchDatagram = Demo.HelloPrx.uncheckedCast(twoway.ice_batchDatagram())
-
- secure = False
- timeout = -1
-
- menu()
-
- c = None
- while c != 'x':
- try:
- c = raw_input("==> ")
- if c == 't':
- twoway.sayHello()
- elif c == 'o':
- oneway.sayHello()
- elif c == 'O':
- batchOneway.sayHello()
- elif c == 'd':
- if secure:
- print "secure datagrams are not supported"
- else:
- datagram.sayHello()
- elif c == 'D':
- if secure:
- print "secure datagrams are not supported"
- else:
- batchDatagram.sayHello()
- elif c == 'f':
- communicator.flushBatchRequests()
- elif c == 'T':
- if timeout == -1:
- timeout = 2000
- else:
- timeout = -1
-
- twoway = Demo.HelloPrx.uncheckedCast(twoway.ice_timeout(timeout))
- oneway = Demo.HelloPrx.uncheckedCast(oneway.ice_timeout(timeout))
- batchOneway = Demo.HelloPrx.uncheckedCast(batchOneway.ice_timeout(timeout))
-
- if timeout == -1:
- print "timeout is now switched off"
- else:
- print "timeout is now set to 2000ms"
- elif c == 'S':
- secure = not secure
-
- twoway = Demo.HelloPrx.uncheckedCast(twoway.ice_secure(secure))
- oneway = Demo.HelloPrx.uncheckedCast(oneway.ice_secure(secure))
- batchOneway = Demo.HelloPrx.uncheckedCast(batchOneway.ice_secure(secure))
- datagram = Demo.HelloPrx.uncheckedCast(datagram.ice_secure(secure))
- batchDatagram = Demo.HelloPrx.uncheckedCast(batchDatagram.ice_secure(secure))
-
- if secure:
- print "secure mode is now on"
- else:
- print "secure mode is now off"
- elif c == 's':
- twoway.shutdown()
- elif c == 'x':
- pass # Nothing to do
- elif c == '?':
- menu()
- else:
- print "unknown command `" + c + "'"
- menu()
- except EOFError:
- break
-
- return True
-
-communicator = None
-try:
- properties = Ice.createProperties()
- properties.load("config")
- communicator = Ice.initializeWithProperties(sys.argv, properties)
- status = run(sys.argv, communicator)
-except:
- traceback.print_exc()
- status = False
-
-if communicator:
- try:
- communicator.destroy()
- except:
- traceback.print_exc()
- status = False
-
-sys.exit(not status)
+class Client(Ice.Application):
+ def run(self, args):
+ properties = self.communicator().getProperties()
+ refProperty = 'Hello.Proxy'
+ proxy = properties.getProperty(refProperty)
+ if len(proxy) == 0:
+ print args[0] + ": property `" + refProperty + "' not set"
+ return False
+
+ twoway = Demo.HelloPrx.checkedCast(\
+ self.communicator().stringToProxy(proxy).ice_twoway().ice_timeout(-1).ice_secure(False))
+ if not twoway:
+ print args[0] + ": invalid proxy"
+ return False
+
+ oneway = Demo.HelloPrx.uncheckedCast(twoway.ice_oneway())
+ batchOneway = Demo.HelloPrx.uncheckedCast(twoway.ice_batchOneway())
+ datagram = Demo.HelloPrx.uncheckedCast(twoway.ice_datagram())
+ batchDatagram = Demo.HelloPrx.uncheckedCast(twoway.ice_batchDatagram())
+
+ secure = False
+ timeout = -1
+
+ menu()
+
+ c = None
+ while c != 'x':
+ try:
+ c = raw_input("==> ")
+ if c == 't':
+ twoway.sayHello()
+ elif c == 'o':
+ oneway.sayHello()
+ elif c == 'O':
+ batchOneway.sayHello()
+ elif c == 'd':
+ if secure:
+ print "secure datagrams are not supported"
+ else:
+ datagram.sayHello()
+ elif c == 'D':
+ if secure:
+ print "secure datagrams are not supported"
+ else:
+ batchDatagram.sayHello()
+ elif c == 'f':
+ communicator.flushBatchRequests()
+ elif c == 'T':
+ if timeout == -1:
+ timeout = 2000
+ else:
+ timeout = -1
+
+ twoway = Demo.HelloPrx.uncheckedCast(twoway.ice_timeout(timeout))
+ oneway = Demo.HelloPrx.uncheckedCast(oneway.ice_timeout(timeout))
+ batchOneway = Demo.HelloPrx.uncheckedCast(batchOneway.ice_timeout(timeout))
+
+ if timeout == -1:
+ print "timeout is now switched off"
+ else:
+ print "timeout is now set to 2000ms"
+ elif c == 'S':
+ secure = not secure
+
+ twoway = Demo.HelloPrx.uncheckedCast(twoway.ice_secure(secure))
+ oneway = Demo.HelloPrx.uncheckedCast(oneway.ice_secure(secure))
+ batchOneway = Demo.HelloPrx.uncheckedCast(batchOneway.ice_secure(secure))
+ datagram = Demo.HelloPrx.uncheckedCast(datagram.ice_secure(secure))
+ batchDatagram = Demo.HelloPrx.uncheckedCast(batchDatagram.ice_secure(secure))
+
+ if secure:
+ print "secure mode is now on"
+ else:
+ print "secure mode is now off"
+ elif c == 's':
+ twoway.shutdown()
+ elif c == 'x':
+ pass # Nothing to do
+ elif c == '?':
+ menu()
+ else:
+ print "unknown command `" + c + "'"
+ menu()
+ except EOFError:
+ break
+
+ return True
+
+app = Client()
+sys.exit(app.main(sys.argv, "config"))