4 using Thrift.Transport;
9 using System.Collections.Generic;
13 public class TZmqServer
16 TProcessor _processor;
18 void debug (string msg)
20 //Uncomment to enable debug
21 // Console.WriteLine (msg);
24 public TZmqServer (TProcessor processor, Context ctx, String endpoint, SocketType sockType)
26 new TSimpleServer (processor,null);
27 _socket = ctx.Socket (sockType);
28 _socket.Bind (endpoint);
29 _processor = processor;
32 public void ServeOne ()
34 debug ("Server_ServeOne");
35 Byte[] msg = _socket.Recv ();
36 MemoryStream istream = new MemoryStream (msg);
37 MemoryStream ostream = new MemoryStream ();
38 TProtocol tProtocol = new TBinaryProtocol (new TStreamTransport (istream, ostream));
39 _processor.Process (tProtocol, tProtocol);
41 if (ostream.Length != 0) {
42 byte[] newBuf = new byte[ostream.Length];
43 Array.Copy (ostream.GetBuffer (), newBuf, ostream.Length);
44 debug (string.Format ("Server_ServeOne sending {0}b", ostream.Length));
45 _socket.Send (newBuf);