Roger Meier | 87e4980 | 2011-04-19 19:47:03 +0000 | [diff] [blame] | 1 | using System; |
| 2 | using System.Threading; |
| 3 | using Thrift.Protocol; |
| 4 | using ZMQ; |
| 5 | using ZmqServer; |
| 6 | using ZmqClient; |
| 7 | |
| 8 | namespace ZmqServer |
| 9 | { |
| 10 | class MainClass |
| 11 | { |
| 12 | public static void Main (string[] args) |
| 13 | { |
| 14 | new Thread(Server.serve).Start(); |
| 15 | Client.work(); |
| 16 | } |
| 17 | |
| 18 | static class Server{ |
| 19 | public static void serve(){ |
| 20 | StorageHandler s=new StorageHandler(); |
| 21 | Storage.Processor p=new Storage.Processor(s); |
| 22 | |
| 23 | ZMQ.Context c=new ZMQ.Context(); |
| 24 | |
| 25 | TZmqServer tzs=new TZmqServer(p,c,"tcp://127.0.0.1:9090",ZMQ.SocketType.PAIR); |
| 26 | tzs.Serve(); |
| 27 | } |
| 28 | |
| 29 | class StorageHandler:Storage.Iface{ |
| 30 | int val=0; |
| 31 | |
| 32 | public void incr(int amount){ |
| 33 | val+=amount; |
| 34 | Console.WriteLine("incr({0})",amount); |
| 35 | } |
| 36 | |
| 37 | public int get(){ |
| 38 | return val; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | static class Client{ |
| 44 | public static void work() |
| 45 | { |
| 46 | Context ctx=new Context(); |
| 47 | TZmqClient tzc=new TZmqClient(ctx,"tcp://127.0.0.1:9090",SocketType.PAIR); |
| 48 | TBinaryProtocol p=new TBinaryProtocol(tzc); |
| 49 | |
| 50 | Storage.Client client=new Storage.Client(p); |
| 51 | tzc.Open(); |
| 52 | |
| 53 | Console.WriteLine(client.@get()); |
| 54 | client.incr(1); |
| 55 | client.incr(41); |
| 56 | Console.WriteLine(client.@get()); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |