當前位置: 首頁>>代碼示例>>C#>>正文


C# Agent.SendOneWay方法代碼示例

本文整理匯總了C#中Agent.SendOneWay方法的典型用法代碼示例。如果您正苦於以下問題:C# Agent.SendOneWay方法的具體用法?C# Agent.SendOneWay怎麽用?C# Agent.SendOneWay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Agent的用法示例。


在下文中一共展示了Agent.SendOneWay方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        static void Main(string[] args)
        {
            if(args.Length != 1)
            {
                Console.WriteLine(
                    "expecting one parameter: " +
                    "publisher destination");
                return;
            }

            String publisherAddress = args[0];

            try
            {
                Agent subscriberAgent = new Agent();

                // prepare subscription update callback

                string updateObjectName =
                    "update_handler";

                subscriberAgent.RegisterObject(
                    updateObjectName, updateHandler);

                // subscribe to the producer

                Parameters param = new Parameters();
                param.SetString(
                    "destination_object", updateObjectName);

                subscriberAgent.SendOneWay(publisherAddress,
                    "random_number", "subscribe", param);

                Console.WriteLine(
                    "subscribed, waiting for updates");

                // block forever
                // and receive updates in background
                while(true)
                {
                    Thread.Sleep(10000);
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(
                    "error: {0}", ex.Message);
            }
        }
開發者ID:morambro,項目名稱:TrainProject,代碼行數:49,代碼來源:Subscriber.cs

示例2: Main

        static void Main(string[] args)
        {
            if(args.Length != 1)
            {
                Console.WriteLine(
                    "expecting one parameter: server destination");
                return;
            }

            string serverAddress = args[0];

            try
            {
                Agent clientAgent = new Agent();

                // read lines of text from standard input
                // and post each one for transmission

                string inputLine = null;
                while((inputLine = Console.ReadLine()) != null)
                {
                    Parameters param = new Parameters();

                    // the "content" field name is arbitrary,
                    // but needs to be recognized at the server side

                    param.SetString("content", inputLine);

                    clientAgent.SendOneWay(serverAddress,
                        "printer", "print", param);
                }

                clientAgent.Close();
            }
            catch(Exception ex)
            {
                Console.WriteLine(
                   "error: {0}", ex.Message);
            }
        }
開發者ID:morambro,項目名稱:TrainProject,代碼行數:40,代碼來源:Client.cs

示例3: Main

        static void Main(string[] args)
        {
            if(args.Length != 1 && args.Length != 4)
            {
                Console.WriteLine(
                    "need 1 or 4 parameters:\n" +
                    "   - server address\n" +
                    "   - outgoing high water mark\n" +
                    "   - outgoing low water mark\n" +
                    "   - number of iterations\n" +
                    "If only server address is given," +
                    " the limits will have default values" +
                    " and the loop will be infinite");
                return;
            }

            string serverAddress = args[0];
            int numOfIterations = -1;

            Parameters options = new Parameters();
            if(args.Length == 4)
            {
                int outgoingHighWaterMark;
                int outgoingLowWaterMark;

                try
                {
                    outgoingHighWaterMark = int.Parse(args[1]);
                    outgoingLowWaterMark = int.Parse(args[2]);
                    numOfIterations = int.Parse(args[3]);
                }
                catch(FormatException)
                {
                    Console.WriteLine("invalid arguments");
                    return;
                }

                options.SetInteger("outgoing_high_water_mark",
                    outgoingHighWaterMark);
                options.SetInteger("outgoing_low_water_mark",
                    outgoingLowWaterMark);
            }

            try
            {
                Agent clientAgent = new Agent(options);

                Parameters param = new Parameters();

                int index = 1;
                while(true)
                {
                    param.SetInteger("index", index);

                    clientAgent.SendOneWay(serverAddress,
                        "object", "message", param);

                    Console.WriteLine(
                        "posted message " + index);

                    if(numOfIterations > 0)
                    {
                        if(index == numOfIterations)
                        {
                            break;
                        }
                    }

                    ++index;
                }

                clientAgent.Close();

            }
            catch(Exception ex)
            {
                Console.WriteLine(
                    "error: {0}", ex.Message);
            }
        }
開發者ID:morambro,項目名稱:TrainProject,代碼行數:80,代碼來源:Client.cs


注:本文中的Agent.SendOneWay方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。