Ejemplo n.º 1
0
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("usage: local_lat <bind-to> <message-size> <roundtrip-count>");
                return(1);
            }

            string bindTo         = args[0];
            int    messageSize    = int.Parse(args[1]);
            int    roundtripCount = int.Parse(args[2]);

            var context   = ZMQ.CtxNew();
            var repSocket = ZMQ.Socket(context, ZmqSocketType.Rep);

            repSocket.Bind(bindTo);

            for (int i = 0; i != roundtripCount; i++)
            {
                Msg message = repSocket.Recv(SendReceiveOptions.None);
                if (ZMQ.MsgSize(message) != messageSize)
                {
                    Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize);
                    return(-1);
                }

                repSocket.Send(message, SendReceiveOptions.None);
            }

            repSocket.Close();
            context.Terminate();

            return(0);
        }
Ejemplo n.º 2
0
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("usage: remote_thr <connect-to> <message-size> <message-count>");
                return(1);
            }

            string connectTo    = args[0];
            int    messageSize  = int.Parse(args[1]);
            int    messageCount = int.Parse(args[2]);

            var context    = ZMQ.CtxNew();
            var pushSocket = ZMQ.Socket(context, ZmqSocketType.Push);

            pushSocket.Connect(connectTo);

            for (int i = 0; i != messageCount; i++)
            {
                var message = new Msg();
                message.InitPool(messageSize);
                pushSocket.Send(ref message, SendReceiveOptions.None);
                message.Close();
            }

            pushSocket.Close();
            context.Terminate();

            return(0);
        }
Ejemplo n.º 3
0
        public void ShouldAllowInfinitePolling()
        {
            Ctx        contextNew = ZMQ.CtxNew();
            SocketBase receiver   = ZMQ.Socket(contextNew, ZmqSocketType.Dealer);

            ZMQ.Bind(receiver, "inproc://test");

            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(500);
                SocketBase sender = ZMQ.Socket(contextNew, ZmqSocketType.Dealer);
                ZMQ.Connect(sender, "inproc://test");
                ZMQ.Send(sender, "ping", SendReceiveOptions.None);
                ZMQ.Close(sender);
            });

            var pollItems = new PollItem[] { new PollItem(receiver, PollEvents.PollIn) };

            Assert.DoesNotThrow(() => ZMQ.Poll(pollItems, -1));

            var msg = ZMQ.Recv(receiver, SendReceiveOptions.DontWait);

            var actual = Encoding.ASCII.GetString(msg.Data, 0, msg.Size);

            Assert.AreEqual("ping", actual);

            ZMQ.Close(receiver);
            ZMQ.Term(contextNew);
        }
Ejemplo n.º 4
0
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("usage: local_thr <bind-to> <message-size> <message-count>");
                return(1);
            }

            string bindTo       = args[0];
            int    messageSize  = int.Parse(args[1]);
            int    messageCount = int.Parse(args[2]);

            var context    = ZMQ.CtxNew();
            var pullSocket = ZMQ.Socket(context, ZmqSocketType.Pull);

            pullSocket.Bind(bindTo);

            var message = new Msg();

            message.InitEmpty();

            pullSocket.Recv(ref message, SendReceiveOptions.None);

            var stopWatch = Stopwatch.StartNew();

            for (int i = 0; i != messageCount - 1; i++)
            {
                pullSocket.Recv(ref message, SendReceiveOptions.None);
                if (message.Size != messageSize)
                {
                    Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize);
                    return(-1);
                }
            }
            stopWatch.Stop();
            var millisecondsElapsed = stopWatch.ElapsedMilliseconds;

            if (millisecondsElapsed == 0)
            {
                millisecondsElapsed = 1;
            }

            message.Close();

            double messagesPerSecond = (double)messageCount / millisecondsElapsed * 1000;
            double megabits          = messagesPerSecond * messageSize * 8 / 1000000;

            Console.WriteLine("message size: {0} [B]", messageSize);
            Console.WriteLine("message count: {0}", messageCount);
            Console.WriteLine("mean throughput: {0:0.000} [msg/s]", messagesPerSecond);
            Console.WriteLine("mean throughput: {0:0.000} [Mb/s]", megabits);

            pullSocket.Close();
            context.Terminate();

            return(0);
        }
Ejemplo n.º 5
0
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("usage: remote_lat remote_lat <connect-to> <message-size> <roundtrip-count>");
                return(1);
            }

            string connectTo      = args[0];
            int    messageSize    = int.Parse(args[1]);
            int    roundtripCount = int.Parse(args[2]);

            var context   = ZMQ.CtxNew();
            var reqSocket = ZMQ.Socket(context, ZmqSocketType.Req);

            reqSocket.Connect(connectTo);

            var message = new Msg();

            message.InitPool(messageSize);

            var stopWatch = Stopwatch.StartNew();

            for (int i = 0; i != roundtripCount; i++)
            {
                reqSocket.Send(ref message, SendReceiveOptions.None);

                reqSocket.Recv(ref message, SendReceiveOptions.None);
                if (message.Size != messageSize)
                {
                    Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize);
                    return(-1);
                }
            }

            stopWatch.Stop();

            message.Close();

            double elapsedMicroseconds = stopWatch.ElapsedTicks * 1000000 / Stopwatch.Frequency;
            double latency             = elapsedMicroseconds / (roundtripCount * 2);

            Console.WriteLine("message size: {0} [B]", messageSize);
            Console.WriteLine("roundtrip count: {0}", roundtripCount);
            Console.WriteLine("average latency: {0:0.000} [µs]", latency);

            reqSocket.Close();
            context.Terminate();

            return(0);
        }
Ejemplo n.º 6
0
        public NetMQSocket CreateSocket(ZmqSocketType socketType)
        {
            var socketHandle = ZMQ.Socket(m_ctx, socketType);

            switch (socketType)
            {
            case ZmqSocketType.Pair:
                return(new PairSocket(socketHandle));

            case ZmqSocketType.Pub:
                return(new PublisherSocket(socketHandle));

            case ZmqSocketType.Sub:
                return(new SubscriberSocket(socketHandle));

            case ZmqSocketType.Req:
                return(new RequestSocket(socketHandle));

            case ZmqSocketType.Rep:
                return(new ResponseSocket(socketHandle));

            case ZmqSocketType.Dealer:
                return(new DealerSocket(socketHandle));

            case ZmqSocketType.Router:
                return(new RouterSocket(socketHandle));

            case ZmqSocketType.Pull:
                return(new PullSocket(socketHandle));

            case ZmqSocketType.Push:
                return(new PushSocket(socketHandle));

            case ZmqSocketType.Xpub:
                return(new XPublisherSocket(socketHandle));

            case ZmqSocketType.Xsub:
                return(new XSubscriberSocket(socketHandle));

            case ZmqSocketType.Stream:
                return(new StreamSocket(socketHandle));

            default:
                throw new ArgumentOutOfRangeException("socketType");
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create xsub socket
        /// </summary>
        /// <returns></returns>
        public XSubscriberSocket CreateXSubscriberSocket()
        {
            var socketHandle = ZMQ.Socket(m_ctx, ZmqSocketType.Xsub);

            return(new XSubscriberSocket(socketHandle));
        }
Ejemplo n.º 8
0
        public StreamSocket CreateStreamSocket()
        {
            var socketHandle = ZMQ.Socket(m_ctx, ZmqSocketType.Stream);

            return(new StreamSocket(socketHandle));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Create pair socket
        /// </summary>
        /// <returns></returns>
        public PairSocket CreatePairSocket()
        {
            var socketHandle = ZMQ.Socket(m_ctx, ZmqSocketType.Pair);

            return(new PairSocket(socketHandle));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Create pull socket
        /// </summary>
        /// <returns></returns>
        public PullSocket CreatePullSocket()
        {
            var socketHandle = ZMQ.Socket(m_ctx, ZmqSocketType.Pull);

            return(new PullSocket(socketHandle));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create xpublisher socket
        /// </summary>
        /// <returns></returns>
        public XPublisherSocket CreateXPublisherSocket()
        {
            var socketHandle = ZMQ.Socket(m_ctx, ZmqSocketType.Xpub);

            return(new XPublisherSocket(socketHandle));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Create router socket
        /// </summary>
        /// <returns></returns>
        public RouterSocket CreateRouterSocket()
        {
            var socketHandle = ZMQ.Socket(m_ctx, ZmqSocketType.Router);

            return(new RouterSocket(socketHandle));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Create dealer socket
        /// </summary>
        /// <returns></returns>
        public DealerSocket CreateDealerSocket()
        {
            var socketHandle = ZMQ.Socket(m_ctx, ZmqSocketType.Dealer);

            return(new DealerSocket(socketHandle));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Create response socket
        /// </summary>
        /// <returns></returns>
        public ResponseSocket CreateResponseSocket()
        {
            var socketHandle = ZMQ.Socket(m_ctx, ZmqSocketType.Rep);

            return(new ResponseSocket(socketHandle));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Create request socket
        /// </summary>
        /// <returns></returns>
        public RequestSocket CreateRequestSocket()
        {
            var socketHandle = ZMQ.Socket(m_ctx, ZmqSocketType.Req);

            return(new RequestSocket(socketHandle));
        }