当前位置: 首页>>代码示例>>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;未经允许,请勿转载。