コード例 #1
0
        public void TestBundle()
        {
            var listener = new UDPListener(55555);

            var sender1 = new SharpOSC.UDPSender("localhost", 55555);
            var msg1    = new SharpOSC.OscMessage("/test/address1", 23, 42.42f, "hello world", new byte[3] {
                2, 3, 4
            });
            var msg2 = new SharpOSC.OscMessage("/test/address2", 34, 24.24f, "hello again", new byte[5] {
                5, 6, 7, 8, 9
            });
            var dt     = DateTime.Now;
            var bundle = new SharpOSC.OscBundle(Utils.DateTimeToTimetag(dt), msg1, msg2);

            sender1.Send(bundle);
            sender1.Send(bundle);
            sender1.Send(bundle);

            var recv = (OscBundle)listener.Receive();

            recv = (OscBundle)listener.Receive();
            recv = (OscBundle)listener.Receive();


            Assert.AreEqual(dt.Date, recv.Timestamp.Date);
            Assert.AreEqual(dt.Hour, recv.Timestamp.Hour);
            Assert.AreEqual(dt.Minute, recv.Timestamp.Minute);
            Assert.AreEqual(dt.Second, recv.Timestamp.Second);
            //Assert.AreEqual(dt.Millisecond, recv.DateTime.Millisecond); Ventus not accurate enough

            Assert.AreEqual("/test/address1", recv.Messages[0].Address);
            Assert.AreEqual(4, recv.Messages[0].Arguments.Count);
            Assert.AreEqual(23, recv.Messages[0].Arguments[0]);
            Assert.AreEqual(42.42f, recv.Messages[0].Arguments[1]);
            Assert.AreEqual("hello world", recv.Messages[0].Arguments[2]);
            Assert.AreEqual(new byte[3] {
                2, 3, 4
            }, recv.Messages[0].Arguments[3]);

            Assert.AreEqual("/test/address2", recv.Messages[1].Address);
            Assert.AreEqual(4, recv.Messages[1].Arguments.Count);
            Assert.AreEqual(34, recv.Messages[1].Arguments[0]);
            Assert.AreEqual(24.24f, recv.Messages[1].Arguments[1]);
            Assert.AreEqual("hello again", recv.Messages[1].Arguments[2]);
            Assert.AreEqual(new byte[5] {
                5, 6, 7, 8, 9
            }, recv.Messages[1].Arguments[3]);

            listener.Close();
        }
コード例 #2
0
        public void TestBundle()
        {
            var listener = new UDPListener(55555);

            var sender1 = new SharpOSC.UDPSender("localhost", 55555);
            var msg1 = new SharpOSC.OscMessage("/test/address1", 23, 42.42f, "hello world", new byte[3] { 2, 3, 4 });
            var msg2 = new SharpOSC.OscMessage("/test/address2", 34, 24.24f, "hello again", new byte[5] { 5, 6, 7, 8, 9 });
            var dt = DateTime.Now;
            var bundle = new SharpOSC.OscBundle(Utils.DateTimeToTimetag(dt), msg1, msg2);

            sender1.Send(bundle);
            sender1.Send(bundle);
            sender1.Send(bundle);

            var recv = (OscBundle)listener.Receive();
            recv = (OscBundle)listener.Receive();
            recv = (OscBundle)listener.Receive();

            Assert.AreEqual(dt.Date, recv.Timestamp.Date);
            Assert.AreEqual(dt.Hour, recv.Timestamp.Hour);
            Assert.AreEqual(dt.Minute, recv.Timestamp.Minute);
            Assert.AreEqual(dt.Second, recv.Timestamp.Second);
            //Assert.AreEqual(dt.Millisecond, recv.DateTime.Millisecond); Ventus not accurate enough

            Assert.AreEqual("/test/address1", recv.Messages[0].Address);
            Assert.AreEqual(4, recv.Messages[0].Arguments.Count);
            Assert.AreEqual(23, recv.Messages[0].Arguments[0]);
            Assert.AreEqual(42.42f, recv.Messages[0].Arguments[1]);
            Assert.AreEqual("hello world", recv.Messages[0].Arguments[2]);
            Assert.AreEqual(new byte[3] { 2, 3, 4 }, recv.Messages[0].Arguments[3]);

            Assert.AreEqual("/test/address2", recv.Messages[1].Address);
            Assert.AreEqual(4, recv.Messages[1].Arguments.Count);
            Assert.AreEqual(34, recv.Messages[1].Arguments[0]);
            Assert.AreEqual(24.24f, recv.Messages[1].Arguments[1]);
            Assert.AreEqual("hello again", recv.Messages[1].Arguments[2]);
            Assert.AreEqual(new byte[5] { 5, 6, 7, 8, 9 }, recv.Messages[1].Arguments[3]);

            listener.Close();
        }