当前位置: 首页>>代码示例>>C#>>正文


C# Context.Socket方法代码示例

本文整理汇总了C#中Context.Socket方法的典型用法代码示例。如果您正苦于以下问题:C# Context.Socket方法的具体用法?C# Context.Socket怎么用?C# Context.Socket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Context的用法示例。


在下文中一共展示了Context.Socket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main(string[] args)
        {
            using (var context = new Context(1))
            {
                using (Socket sync = context.Socket(SocketType.PULL), publisher = context.Socket(SocketType.PUB))
                {
                    sync.Bind("tcp://*:5564");

                    publisher.HWM = 1;
                    //  Specify swap space in bytes, this covers all subscribers
                    publisher.Swap = 25000000;
                    publisher.Bind("tcp://*:5565");

                    //  Wait for synchronization request
                    sync.Recv();

                    for (int updateNumber = 0; updateNumber < 10; updateNumber++)
                    {
                        publisher.Send("Update " + updateNumber, Encoding.Unicode);
                        Thread.Sleep(1000);
                    }

                    publisher.Send("END", Encoding.Unicode);
                }
            }
        }
开发者ID:rjsmith,项目名称:zguide,代码行数:26,代码来源:durapub2.cs

示例2: Main

        static void Main(string[] args)
        {
            using (var context = new Context(1))
              using (var receiver = context.Socket(SocketType.PULL))
              {
            receiver.Connect("tcp://localhost:5557");

            using (var sender = context.Socket(SocketType.PUSH))
            {
              sender.Connect("tcp://localhost:5558");

              using (var controller = context.Socket(SocketType.SUB))
              {
            controller.Connect("tcp://localhost:5559");
            controller.Subscribe(string.Empty, Encoding.Unicode);

            bool run = true;
            PollItem[] items = new PollItem[2];
            items[0] = receiver.CreatePollItem(IOMultiPlex.POLLIN);
            items[0].PollInHandler += (socket, revents) => ReceiverPollInHandler(socket, sender);
            items[1] = controller.CreatePollItem(IOMultiPlex.POLLIN);
            items[1].PollInHandler += delegate { run = false; };

            //  Process tasks as long as the controller does not signal the end.
            while (run)
            {
              context.Poll(items);
            }
              }
            }
              }
        }
开发者ID:nivertech,项目名称:zguide,代码行数:32,代码来源:taskwork2.cs

示例3: Main

        public static void Main(string[] args)
        {
            using (var context = new Context(1))
            {
                using (Socket frontend = context.Socket(SocketType.SUB), backend = context.Socket(SocketType.PUB))
                {
                    //  This is where the weather server sits
                    frontend.Connect("tcp://127.0.0.1:5556");
                    frontend.Subscribe("", Encoding.Unicode);

                    //  This is our public endpoint for subscribers
                    backend.Bind("tcp://*:8100"); // i use local to be able to run the example, this could be the public ip instead eg. tcp://10.1.1.0:8100

                    //  Shunt messages out to our own subscribers
                    while (true)
                    {
                        bool hasMore = true;
                        while (hasMore)
                        {
                            string message = frontend.Recv(Encoding.Unicode);
                            hasMore = frontend.RcvMore;
                            backend.Send(message, Encoding.Unicode, hasMore ? SendRecvOpt.SNDMORE : SendRecvOpt.NONE);
                        }
                    }
                }
            }
        }
开发者ID:hnkien,项目名称:zguide2,代码行数:27,代码来源:wuproxy.cs

示例4: Main

        public static void Main(string[] args)
        {
            using (var context = new Context(1))
            {
                using (Socket receiver = context.Socket(SocketType.PULL), controller = context.Socket(SocketType.PUB))
                {
                    receiver.Bind("tcp://*:5558");
                    controller.Bind("tcp://*:5559");

                    //  Wait for start of batch
                    receiver.Recv();

                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    const int tasksToConfirm = 100;
                    for (int taskNumber = 0; taskNumber < tasksToConfirm; taskNumber++)
                    {
                        string message = receiver.Recv(Encoding.Unicode);
                        Console.WriteLine(taskNumber % 10 == 0 ? ":" : ".");
                    }

                    stopwatch.Stop();
                    Console.WriteLine("Total elapsed time: {0}", stopwatch.ElapsedMilliseconds);

                    controller.Send("KILL", Encoding.Unicode);
                }
            }
        }
开发者ID:hnkien,项目名称:zguide2,代码行数:29,代码来源:tasksink2.cs

示例5: Main

        public static void Main(string[] args)
        {
            using (var context = new Context(1))
            {
                //  Connect to task ventilator and weather server
                using (Socket receiver = context.Socket(SocketType.PULL), subscriber = context.Socket(SocketType.SUB))
                {
                    receiver.Connect("tcp://localhost:5557");
                    subscriber.Connect("tcp://localhost:5556");
                    subscriber.Subscribe("10001 ", Encoding.Unicode);

                    var items = new PollItem[2];
                    items[0] = receiver.CreatePollItem(IOMultiPlex.POLLIN);
                    items[0].PollInHandler += ReceiverPollInHandler;
                    items[1] = subscriber.CreatePollItem(IOMultiPlex.POLLIN);
                    items[1].PollInHandler += SubscriberPollInHandler;

                    //  Process messages from both sockets
                    while (true)
                    {
                        context.Poll(items, -1);
                    }
                }
            }
        }
开发者ID:hnkien,项目名称:zguide2,代码行数:25,代码来源:mspoller.cs

示例6: Initialize

        public void Initialize(IDatabaseHandler dbHandler)
        {
            GlobalContext = new Context(1);
            ValkWFStepPoller.PollContext = GlobalContext;
            ValkWFActivator.ActContext = GlobalContext;
            ValkQueueWFSteps.QueueContext = GlobalContext;
            //setup our inprocess communication
            ActivatorControlIntraComm = GlobalContext.Socket(SocketType.REQ);
            ActivatorControlIntraComm.Bind("inproc://activatorcontrol");
            //poller requires activator, goes after
            PollerControlIntraComm = GlobalContext.Socket(SocketType.REQ);
            PollerControlIntraComm.Bind("inproc://pollercontrol");

            QueueControlIntraComm = GlobalContext.Socket(SocketType.REQ);
            QueueControlIntraComm.Bind("inproc://queuecontrol");

            //anonymous function to pass in dbhandler without parameterizedthreadstart obscurities
            WFStepQueue = new Thread(() => ValkQueueWFSteps.RunQueue(dbHandler));
            WFStepQueue.Start();

            Activator = new Thread(() => ValkWFActivator.ActivateResponder(dbHandler));
            Activator.Start();

            Poller = new Thread(() => ValkWFStepPoller.StartPolling(dbHandler));
            Poller.Start();
        }
开发者ID:jmlothian,项目名称:ValkyrieWF,代码行数:26,代码来源:ValkController.cs

示例7: Main

    static int Main(string[] argv)
    {
        Context context = new Context(1);

        //  Socket to receive messages on
        Socket receiver = context.Socket(SocketType.PULL);
        sender.Connect("tcp://localhost:5557");

        //  Socket to send messages on
        Socket sender = context.Socket(SocketType.PUSH);
        sender.Connect("tcp://localhost:5557");

        //  Process tasks forever
        while (true) {
            string _string = receiver.Recv(Encoding.Unicode);
            int t;
            t = Convert.ToInt32(_string) * 1000;
            //  Simple progress indicator for the viewer;
            Console.WriteLine("{0}.", _string);

            //  Do the work
            Thread.Sleep(t);

            sender.Send("", Encoding.Unicode);
        }

        receiver.Close();
        sender.Close();
        context.Terminate();
        return 0;
    }
开发者ID:gochist,项目名称:zguide,代码行数:31,代码来源:taskwork.cs

示例8: Main

        //  We will do this all in one thread to emphasize the sequence
        //  of events...
        static void Main(string[] args)
        {
            using (Context ctx = new Context(1)) {
                using (Socket client = ctx.Socket(SocketType.ROUTER),
                    worker = ctx.Socket(SocketType.REP)) {

                    client.Bind("inproc://routing");
                    worker.StringToIdentity("A", Encoding.Unicode);
                    worker.Connect("inproc://routing");

                    //  Wait for the worker to connect so that when we send a message
                    //  with routing envelope, it will actually match the worker...
                    Thread.Sleep(1000);

                    //  Send papa address, address stack, empty part, and request
                    client.SendMore("A", Encoding.Unicode);
                    client.SendMore("address 3", Encoding.Unicode);
                    client.SendMore("address 2", Encoding.Unicode);
                    client.SendMore("address 1", Encoding.Unicode);
                    client.SendMore("", Encoding.Unicode);
                    client.Send("This is the workload", Encoding.Unicode);

                    //  Worker should get just the workload
                    ZHelpers.Dump(worker, Encoding.Unicode);

                    //  We don't play with envelopes in the worker
                    worker.Send("This is the reply", Encoding.Unicode);

                    //  Now dump what we got off the ROUTER socket...
                    ZHelpers.Dump(client, Encoding.Unicode);
                }
            }
        }
开发者ID:rkern,项目名称:zguide,代码行数:35,代码来源:rtpapa.cs

示例9: Main

        static void Main(string[] args)
        {
            using (Context context = new Context(1)) {
                using (Socket sync = context.Socket(SocketType.PULL),
                    publisher = context.Socket(SocketType.PUB)) {

                    //  Subscriber tells us when it's ready here
                    sync.Bind("tcp://*:5564");

                    //  We send updates via this socket
                    publisher.Bind("tcp://*:5565");

                    //  Prevent publisher overflow from slow subscribers
                    publisher.HWM = 1;
                    //  Specify swap space in bytes, this covers all subscribers
                    publisher.Swap = 25000000;

                    //  Wait for synchronization request
                    sync.Recv();

                    //  Now broadcast exactly 10 updates with pause
                    for (int updateNbr = 0; updateNbr < 10; updateNbr++) {
                        publisher.Send("Update " + updateNbr, Encoding.Unicode);
                        Thread.Sleep(1000);
                    }
                    publisher.Send("END", Encoding.Unicode);
                    Thread.Sleep(1000);   //  Give 0MQ/2.0.x time to flush output
                }
            }
        }
开发者ID:Neopallium,项目名称:zguide,代码行数:30,代码来源:durapub2.cs

示例10: Main

        public static void Main(string[] args)
        {
            using (var context = new Context(1))
            {
                using (Socket publisher = context.Socket(SocketType.PUB), syncService = context.Socket(SocketType.REP))
                {
                    publisher.Bind("tcp://*:5561");
                    syncService.Bind("tcp://*:5562");

                    //  Get synchronization from subscribers
                    const int subscribersToWaitFor = 10;
                    for (int count = 0; count < subscribersToWaitFor; count++)
                    {
                        syncService.Recv();
                        syncService.Send("", Encoding.Unicode);
                    }

                    //  Now broadcast exactly 1M updates followed by END
                    const int updatesToSend = 1000000;
                    for (int updateId = 0; updateId < updatesToSend; updateId++)
                    {
                        publisher.Send("Rhubard", Encoding.Unicode);
                    }

                    publisher.Send("END", Encoding.Unicode);
                }
            }
        }
开发者ID:hnkien,项目名称:zguide2,代码行数:28,代码来源:syncpub.cs

示例11: Main

        static void Main(string[] args)
        {
            using (Context context = new Context(1)) {
                using (Socket subscriber = context.Socket(SocketType.SUB),
                    syncClient = context.Socket(SocketType.REQ)) {

                    //  First, connect our subscriber socket
                    subscriber.Connect("tcp://localhost:5561");
                    subscriber.Subscribe("", Encoding.Unicode);

                    //  Second, synchronize with publisher
                    syncClient.Connect("tcp://localhost:5562");

                    //  - send a synchronization request
                    syncClient.Send("", Encoding.Unicode);
                    //  - wait for synchronization reply
                    syncClient.Recv();

                    //  Third, get our updates and report how many we got
                    int nbrUpdates = 0;
                    while (!subscriber.Recv(Encoding.Unicode).Equals("END")) {
                        nbrUpdates++;
                    }
                    Console.WriteLine("Received {0} updates.", nbrUpdates);
                }
            }
        }
开发者ID:nivertech,项目名称:zguide,代码行数:27,代码来源:syncsub.cs

示例12: Main

        static void Main(string[] args)
        {
            //  Prepare our context
            using (Context context = new Context(1)) {
                //  Sockets to send and receive messages on
                using (Socket receiver = context.Socket(SocketType.PULL),
                    sender = context.Socket(SocketType.PUSH)) {
                    receiver.Connect("tcp://localhost:5557");
                    sender.Connect("tcp://localhost:5558");

                    //  Process tasks forever
                    while (true) {
                        string message = receiver.Recv(Encoding.Unicode);
                        //  Simple progress indicator for the viewer
                        Console.Clear();
                        Console.WriteLine("{0}.", message);

                        //  Do the work
                        Thread.Sleep(Convert.ToInt32(message));

                        //  Send results to sink
                        sender.Send("", Encoding.Unicode);
                    }
                }
            }
        }
开发者ID:hnkien,项目名称:zguide2,代码行数:26,代码来源:taskworker.cs

示例13: Main

        static void Main(string[] args)
        {
            using (var context = new Context(1))
            {
                using (Socket
                        receiver = context.Socket(SocketType.PULL),
                        sender = context.Socket(SocketType.PUSH))
                {

                    receiver.Connect("tcp://localhost:5557");
                    sender.Connect("tcp://localhost:5558");

                    while (true)
                    {
                        string task = receiver.Recv(Encoding.Unicode);

                        Console.WriteLine("{0}.", task);

                        int sleepTime = Convert.ToInt32(task);
                        Thread.Sleep(sleepTime);

                        sender.Send("", Encoding.Unicode);
                    }

                }
            }
        }
开发者ID:JoeHosman,项目名称:ZeroQueueWork,代码行数:27,代码来源:Program.cs

示例14: AsyncReturn

 public AsyncReturn(Context context, string frontendAddr, string backendAddr, MessageProcessor msgProc)
     : base(context.Socket(SocketType.XREP), context.Socket(SocketType.PULL))
 {
     _messageProcessor = msgProc;
     _frontend.Bind(frontendAddr);
     _backend.Bind(backendAddr);
 }
开发者ID:castlestronghold,项目名称:clrzmq2,代码行数:7,代码来源:Device.cs

示例15: RRBroker

 public RRBroker()
 {
     //  Prepare our context and sockets
     context = new Context(1);
     frontend = context.Socket(SocketType.XREP);
     backend = context.Socket(SocketType.XREQ);
     frontend.Bind("tcp://*:5559");
     backend.Bind("tcp://*:5560");
 }
开发者ID:nivertech,项目名称:zguide,代码行数:9,代码来源:rrbroker.cs


注:本文中的Context.Socket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。