Beispiel #1
0
        public void Disposing()
        {
            var server = new ZetaUdpSubscriber();

            Assert.False(server.IsDisposed);
            server.Dispose();
            Assert.True(server.IsDisposed);
        }
Beispiel #2
0
        public void Starting()
        {
            var server = new ZetaUdpSubscriber();

            Assert.False(server.IsStarted);
            server.Start("127.0.0.1:56789");
            Assert.True(server.IsStarted);
            server.Dispose();
            Assert.False(server.IsStarted);
        }
Beispiel #3
0
        public void FullRun()
        {
            Byte expected = 0;

            // Start server
            var server = new ZetaUdpPublisher();

            server.Start(1000);

            // Start client
            var client = new ZetaUdpSubscriber();

            client.ReadTimeout = new TimeSpan(0, 0, 1);
            client.Start("127.0.0.1:1000");

            // Start reading
            var aborted      = false;
            var readerThread = Task.Run(() => {
                try {
                    while (!client.IsDisposed)
                    {
                        var msg = client.Read <BinaryMessage>(out var topic, out var revision);
                        Assert.Equal((UInt32)5, topic);
                        Assert.Equal(expected, revision);
                        Assert.Equal(expected, msg.Value[0]);
                        expected++;
                    }
                } catch (TimedOutException) {
                } finally {
                    aborted = true;
                }
            });


            Thread.Sleep(100);
            server.Publish(new BinaryMessage(new Byte[] { 0 }), 5);

            Thread.Sleep(100);
            server.Publish(new BinaryMessage(new Byte[] { 1 }), 5);

            Thread.Sleep(100);
            server.Publish(new BinaryMessage(new Byte[] { 2 }), 5);

            Thread.Sleep(100);
            Assert.Equal((Byte)3, expected);

            client.Dispose();
            Thread.Sleep(1000);
            Assert.True(aborted);
            server.Dispose();
        }
Beispiel #4
0
        static void Main(String[] args)
        {
            var rnd = new Random();

            Trace.Listeners.Add(new Listener());

            // Start server
            var server = new ZetaUdpPublisher();

            server.Start(1000); // Listed on UDP port 1000

            // Start client
            var client = new ZetaUdpSubscriber();

            client.Start("127.0.0.1:1000");

            // Start reading
            var readerThread = Task.Run(() => {
                while (!client.IsDisposed)
                {
                    var msg = client.Read <StringMessage>();
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine($"> {msg.Value}");
                }
            });

            // Send payloads
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Sending payloads...");
            server.Publish(new StringMessage("Topic 0, message 1"), 0);
            server.Publish(new StringMessage("Topic 1, message 1"), 1);
            server.Publish(new StringMessage("Topic 1, message 2"), 1);
            server.Publish(new StringMessage("Topic 2, message 1"), 2);

            for (Byte i = 2; i <= 50; i++)
            {
                server.Publish(new StringMessage($"Topic 1, message {i}"), 1);
                Thread.Sleep(rnd.Next(0, 1000));
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Killing client.");
            readerThread.Dispose();
            client.Dispose();

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Done.");

            Console.ReadKey(true);
        }