コード例 #1
0
ファイル: InteropTests.cs プロジェクト: xiangzhi/psi
        private void NetMQTransportMultiTopicTest()
        {
            const string topic0  = "test-topic0";
            const string topic1  = "test-topic1";
            string       address = "tcp://localhost:12345";

            // start client
            ListObservable <double> results0;
            ListObservable <int>    results1;
            var complete0 = false;
            var complete1 = false;

            using (var p = Pipeline.Create())
            {
                Console.WriteLine("Starting client...");
                var client0 = new NetMQSource <double>(p, topic0, address, JsonFormat.Instance);
                client0.Do(x => complete0 = (x == 9)).Do(x => Console.WriteLine($"MSG0: {x}"));
                results0 = client0.ToObservable().ToListObservable();
                var client1 = new NetMQSource <int>(p, topic1, address, JsonFormat.Instance);
                client1.Do(x => complete1 = (x == 9)).Do(x => Console.WriteLine($"MSG1: {x}"));
                results1 = client1.ToObservable().ToListObservable();
                p.RunAsync();

                Thread.Sleep(1000); // give time to open TCP port

                // start server - run to end of finite generator
                Console.WriteLine("Starting server...");
                using (var q = Pipeline.Create())
                {
                    var gen0      = Generators.Range(q, 0, 10, TimeSpan.FromMilliseconds(10)).Select(x => (double)x);
                    var gen1      = Generators.Range(q, 0, 10, TimeSpan.FromMilliseconds(10));
                    var server    = new NetMQWriter(q, address, JsonFormat.Instance);
                    var receiver0 = server.AddTopic <double>(topic0);
                    var receiver1 = server.AddTopic <int>(topic1);
                    gen0.PipeTo(receiver0);
                    gen1.PipeTo(receiver1);
                    q.Run();
                }

                Console.WriteLine("Waiting...");
                while (!complete0 || !complete1)
                {
                    Thread.Sleep(100);
                }
            }

            Assert.IsTrue(Enumerable.SequenceEqual(results0.AsEnumerable(), new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
            Assert.IsTrue(Enumerable.SequenceEqual(results1.AsEnumerable(), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
        }
コード例 #2
0
ファイル: InteropTests.cs プロジェクト: xiangzhi/psi
        private void NetMQTransportTest()
        {
            const string topic   = "test-topic";
            string       address = "tcp://localhost:12345";

            // start client
            ListObservable <double> results;
            var complete = false;

            using (var p = Pipeline.Create())
            {
                Console.WriteLine("Starting client...");
                var client = new NetMQSource <double>(p, topic, address, JsonFormat.Instance);
                client.Do(x => complete = (x == 9)).Do(x => Console.WriteLine($"MSG: {x}"));
                results = client.ToObservable().ToListObservable();
                p.RunAsync();

                Thread.Sleep(1000); // give time to open TCP port

                // start server - run to end of finite generator
                Console.WriteLine("Starting server...");
                using (var q = Pipeline.Create())
                {
                    var gen    = Generators.Range(q, 0, 10, TimeSpan.FromMilliseconds(10)).Select(x => (double)x);
                    var server = new NetMQWriter <double>(q, topic, address, JsonFormat.Instance);
                    gen.PipeTo(server);
                    q.Run();
                }

                Console.WriteLine("Waiting...");
                while (!complete)
                {
                    Thread.Sleep(100);
                }
            }

            Assert.IsTrue(Enumerable.SequenceEqual(results.AsEnumerable(), new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
        }