diff options
author | Matthew Newhook <matthew@zeroc.com> | 2005-10-26 06:50:12 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2005-10-26 06:50:12 +0000 |
commit | 1a886507b471cf373abde9745022b3758112503c (patch) | |
tree | a841bbe19dd2f0ce33342396ecb4d31cb1e33e96 /cs/demo/IceBox/hello/Client.cs | |
parent | cleanup. (diff) | |
download | ice-1a886507b471cf373abde9745022b3758112503c.tar.bz2 ice-1a886507b471cf373abde9745022b3758112503c.tar.xz ice-1a886507b471cf373abde9745022b3758112503c.zip |
Added C# implementation of IceBox.
Diffstat (limited to 'cs/demo/IceBox/hello/Client.cs')
-rw-r--r-- | cs/demo/IceBox/hello/Client.cs | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/cs/demo/IceBox/hello/Client.cs b/cs/demo/IceBox/hello/Client.cs new file mode 100644 index 00000000000..ab9e4f232d9 --- /dev/null +++ b/cs/demo/IceBox/hello/Client.cs @@ -0,0 +1,147 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +using System; +using Demo; + +public class Client : Ice.Application +{ + private static void menu() + { + Console.WriteLine( + "usage:\n" + + "t: send greeting as twoway\n" + + "o: send greeting as oneway\n" + + "O: send greeting as batch oneway\n" + + "d: send greeting as datagram\n" + + "D: send greeting as batch datagram\n" + + "f: flush all batch requests\n" + + "T: set a timeout\n" + + "x: exit\n" + + "?: help\n"); + } + + public override int run(string[] args) + { + Ice.Properties properties = communicator().getProperties(); + string proxyProperty = "Hello.Proxy"; + string proxy = properties.getProperty(proxyProperty); + if(proxy.Length == 0) + { + Console.Error.WriteLine("property `" + proxyProperty + "' not set"); + return 1; + } + + HelloPrx twoway = HelloPrxHelper.checkedCast( + communicator().stringToProxy(proxy).ice_twoway().ice_timeout(-1).ice_secure(false)); + if(twoway == null) + { + Console.Error.WriteLine("invalid proxy"); + return 1; + } + HelloPrx oneway = HelloPrxHelper.uncheckedCast(twoway.ice_oneway()); + HelloPrx batchOneway = HelloPrxHelper.uncheckedCast(twoway.ice_batchOneway()); + HelloPrx datagram = HelloPrxHelper.uncheckedCast(twoway.ice_datagram()); + HelloPrx batchDatagram = HelloPrxHelper.uncheckedCast(twoway.ice_batchDatagram()); + + int timeout = -1; + + menu(); + + string line = null; + do + { + try + { + Console.Out.Write("==> "); + Console.Out.Flush(); + line = Console.In.ReadLine(); + if(line == null) + { + break; + } + if(line.Equals("t")) + { + twoway.sayHello(); + } + else if(line.Equals("o")) + { + oneway.sayHello(); + } + else if(line.Equals("O")) + { + batchOneway.sayHello(); + } + else if(line.Equals("d")) + { + datagram.sayHello(); + } + else if(line.Equals("D")) + { + batchDatagram.sayHello(); + } + else if(line.Equals("f")) + { + communicator().flushBatchRequests(); + } + else if(line.Equals("T")) + { + if(timeout == -1) + { + timeout = 2000; + } + else + { + timeout = -1; + } + + twoway = HelloPrxHelper.uncheckedCast(twoway.ice_timeout(timeout)); + oneway = HelloPrxHelper.uncheckedCast(oneway.ice_timeout(timeout)); + batchOneway = HelloPrxHelper.uncheckedCast(batchOneway.ice_timeout(timeout)); + + if(timeout == -1) + { + Console.WriteLine("timeout is now switched off"); + } + else + { + Console.WriteLine("timeout is now set to 2000ms"); + } + } + else if(line.Equals("x")) + { + // Nothing to do + } + else if(line.Equals("?")) + { + menu(); + } + else + { + Console.WriteLine("unknown command `" + line + "'"); + menu(); + } + } + catch(System.Exception ex) + { + Console.Error.WriteLine(ex); + } + } + while (!line.Equals("x")); + + return 0; + } + + public static void Main(string[] args) + { + Client app = new Client(); + int status = app.main(args, "config"); + System.Environment.Exit(status); + } +} |