summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/contrib/zeromq/csharp/Main.cs
blob: e66cfe08056e78337f0024ada65bbb44c33c9133 (plain)
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
using System;
using System.Threading;
using Thrift.Protocol;
using ZMQ;
using ZmqServer;
using ZmqClient;

namespace ZmqServer
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			new Thread(Server.serve).Start();
			Client.work();
		}
		
		static class Server{
			public static void serve(){
				StorageHandler s=new StorageHandler();
				Storage.Processor p=new Storage.Processor(s);
				
				ZMQ.Context c=new ZMQ.Context();
				
				TZmqServer tzs=new TZmqServer(p,c,"tcp://127.0.0.1:9090",ZMQ.SocketType.PAIR);
				tzs.Serve();
			}
			
			class StorageHandler:Storage.Iface{
				int val=0;
				
				public void incr(int amount){
					val+=amount;
					Console.WriteLine("incr({0})",amount);
				}
				
				public int get(){
					return val;
				} 
			}
		}
		
		static class Client{
			public static void work()
			{
				Context ctx=new Context();
				TZmqClient tzc=new TZmqClient(ctx,"tcp://127.0.0.1:9090",SocketType.PAIR);
				TBinaryProtocol p=new TBinaryProtocol(tzc);
				
				Storage.Client client=new Storage.Client(p);
				tzc.Open();
				
				Console.WriteLine(client.@get());
				client.incr(1);
				client.incr(41);
				Console.WriteLine(client.@get());
			}
		}
	}
}