Example #1
0
        //  Majordomo Protocol worker example
        //  Uses the mdwrk API to hide all MDP aspects
        public static void MDWorker(string[] args)
        {
            bool verbose = (args.Any(e => e.ToLower().Equals("-v")
                                       || e.ToLower().Equals("--verbose")));
            Console.WriteLine("Verbose: {0}", verbose);

            CancellationTokenSource cts = new CancellationTokenSource();
            Console.CancelKeyPress += (s, ea) =>
            {
                ea.Cancel = true;
                cts.Cancel();
            };

            using (MajordomoWorker session = new MajordomoWorker("tcp://localhost:5555", "echo", verbose))
            {
                ZMessage reply = null;
                while (true)
                {
                    ZMessage request = session.Recv(reply, cts);
                    if (request == null)
                        break; // worker was interrupted
                    reply = request; // Echo is complex
                }
            }
        }
Example #2
0
        //  Majordomo Protocol worker example
        //  Uses the mdwrk API to hide all MDP aspects
        public static void MDWorker(string[] args)
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            Console.CancelKeyPress += (s, ea) =>
            {
                ea.Cancel = true;
                cts.Cancel();
            };

            using (MajordomoWorker session = new MajordomoWorker("tcp://127.0.0.1:5555", "echo", Verbose))
            {
                ZMessage reply = null;
                while (true)
                {
                    ZMessage request = session.Recv(reply, cts);
                    if (request == null)
                        break; // worker was interrupted
                    reply = request; // Echo is complex
                }
            }
        }