Ejemplo n.º 1
0
    public static void Main(string[] args)
    {
        if(args.Length < 1 || args.Length > 2)
        {
            Console.WriteLine("Usage: client.exe <request address> <data address>");
            return;
        }

        var requestAddress = args[0];
        var dataAddress = args[1];
        var zmqContext = new Context();
        var queue = new BlockingCollection<byte[]>();

        var writeThread = new Thread(() =>
            {
                using(var reqSocket = zmqContext.CreateSocket(SocketType.Rep))
                {
                    reqSocket.Bind(requestAddress);

                    for(long count = 0; ; count++)
                    {
                        reqSocket.Recv();
                        reqSocket.Send(queue.Take());

                        if(count % 1000 == 0)
                            Console.WriteLine("Sent {0}", count);
                    }
                }
            });

        var readThread = new Thread(() =>
            {
                using(var dataSocket = zmqContext.CreateSocket(SocketType.Pull))
                {
                    dataSocket.Bind(dataAddress);

                    for(long count = 0; ; count++)
                    {
                        queue.Add(dataSocket.Recv());

                        if(count % 1000 == 0)
                            Console.WriteLine("Received {0}", count);
                    }
                }
            });

        writeThread.Start();
        readThread.Start();

        Console.WriteLine("Press return to quit");
        Console.ReadLine();

        writeThread.Abort();
        readThread.Abort();
    }
Ejemplo n.º 2
0
		static void Main(string[] args)
		{
			using (var ctx = new Context())
			{
				const string MsgReq = "function shall retrieve the value for the option specified by the option_name argument for the ØMQ socket pointed to by the socket argument, and store it in the buffer pointed to by the option_value argument";
				const string MsgReply = "The option_len argument is the size in bytes of the buffer pointed to by option_value; upon successful completion zmq_getsockopt() shall modify the option_len argument to indicate the actual size of the option value stored in the buffer";

				ulong counter = 0;

				using (var repSocket = ctx.CreateSocket(SocketType.Rep))
				{
					repSocket.SetOption(SocketOpt.LINGER, false);
					repSocket.Bind("tcp://0.0.0.0:8801");

					while (true)
					{
						counter++;

						if (counter % 1000 == 0)
						{
							var collCount0 = GC.CollectionCount(0);
							var collCount1 = GC.CollectionCount(1);
							var collCount2 = GC.CollectionCount(2);
						
							Console.WriteLine("Collections on Gen 0 {0}, Gen 1 {1}, Gen 2 {2} ", collCount0, collCount1, collCount2);
						}

						using (var reqSocket = ctx.CreateSocket(SocketType.Req))
						{
							reqSocket.SetOption(SocketOpt.LINGER, false);

							reqSocket.Connect("tcp://127.0.0.1:8801");

							reqSocket.Send(MsgReq);

							var msg = repSocket.Recv();
							var msgStr = Encoding.UTF8.GetString(msg);

							if (MsgReq != msgStr) throw new Exception("MsgReq is different from expected: " + msgStr);

							repSocket.Send(MsgReply);

							msg = reqSocket.Recv();
							msgStr = Encoding.UTF8.GetString(msg);

							if (MsgReply != msgStr) throw new Exception("MsgReply is different from expected: " + msgStr);
						}
					}
				}
			}
		}
Ejemplo n.º 3
0
    public static void Main(string[] args)
    {
        if(args.Length < 1 || args.Length > 2)
        {
            Console.WriteLine("Usage: writer <data address> [message size]");
            return;
        }

        var dataAddress = args[0];
        var messageSize = args.Length == 2 ? Int32.Parse(args[1]) : 1024;

        var messageData = new byte[messageSize];
        for(var i = 0; i < messageData.Length; i++)
            messageData[i] = (byte)(i % Byte.MaxValue);

        using(var zmqContext = new Context())
        using(var dataSocket = zmqContext.CreateSocket(SocketType.Push))
        {
            dataSocket.Connect(dataAddress);

            for(long count = 0; ; count++)
            {
                dataSocket.Send(messageData);

                if(count % 1000 == 0)
                    Console.WriteLine("Sent {0}", count);
            }
        }
    }
Ejemplo n.º 4
0
    public static void Main(string[] args)
    {
        if(args.Length != 1)
        {
            Console.WriteLine("Usage: reader <request address>");
            return;
        }

        var requestAddress = args[0];

        var taskRequestData = new byte[] { 0 };

        using(var zmqContext = new Context())
        using(var reqSocket = zmqContext.CreateSocket(SocketType.Req))
        {
            reqSocket.Connect(requestAddress);

            for(long count = 0; ; count++)
            {
                reqSocket.Send(taskRequestData);
                reqSocket.Recv();

                if(count % 1000 == 0)
                    Console.WriteLine("Sent {0}", count);
            }
        }
    }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("usage: local_thr <bind-to> <message-size> <message-count>");
                Environment.Exit(1);
            }

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

            TimeSpan elapsed;
            using (var ctx = new Context())
            using (var s = ctx.CreateSocket(SocketType.Pull))
            {
                s.Bind(bindTo);

                var msg = s.Recv();

                if (msg.Length != messageSize)
                {
                    Console.WriteLine("message of incorrect size received");
                    Environment.Exit(-1);
                }

                var sw = new Stopwatch();

                sw.Start();
                for (int i = 0; i < messageCount - 1; i++)
                {
                    msg = s.Recv();
                    if (msg.Length != messageSize)
                    {
                        Console.WriteLine("message of incorrect size received");
                        Environment.Exit(-1);
                    }
                }
                sw.Stop();

                elapsed = sw.Elapsed;
            }

            double throughput = messageCount / elapsed.TotalSeconds;
            double megabits = (throughput * messageSize * 8) / (1000000);

            Console.WriteLine("message size: {0} B", messageSize);
            Console.WriteLine("message count: {0}", messageCount);
            Console.WriteLine("mean throughput: {0:0} [msg/s]", throughput);
            Console.WriteLine("mean throughput: {0:0.000} [Mb/s]", megabits);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("usage: remote_thr <connect-to> <message-size> <message-count>");
                Environment.Exit(1);
            }

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

            using (var ctx = new Context())
            using (var s = ctx.CreateSocket(SocketType.Push))
            {
                s.Connect(connectTo);

                var msg = new byte[messageSize];
                for (int i = 0; i < messageCount; i++)
                {
                    s.Send(msg);
                }
            }
        }