コード例 #1
0
        public void RunningClock()
        {
            var receivedUdp = new List <string>();
            var settings    = new ClockSettings()
            {
                IsRunning = true
            };
            var options = ClockServerOptions.Default.Value;

            using (var receiver = new UdpClient(2000, AddressFamily.InterNetwork))
            {
                receiver.JoinMulticastGroup(IPAddress.Parse(options.Multicast.IPAddress), ClockServer.GetLocalIPAddress());
                var state = new State {
                    u = receiver, l = receivedUdp
                };
                using var t      = Task.Factory.StartNew(() => Receiver(receiver, state), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
                using var target = new ClockServer(
                          Options.Create(new ClockServerOptions()
                {
                    Multicast = new MulticastOptions { IntervalSeconds = 1, IPAddress = "239.50.50.20", IsEnabled = true, PortNumber = 2000 },
                    Polling   = new PollingOptions { IsEnabled = true, PortNumber = 2500 },
                    StartTime = TimeSpan.FromHours(5.5),
                    Speed     = 6,
                }));
                {
                }
                target.Start(settings);
                target.StartTick("Test", "password");
                Assert.IsTrue(target.IsRunning);
                Thread.Sleep(5000);
                target.Stop();
                receiver.Close();
                t.Wait();
            }
            Assert.IsTrue(receivedUdp.Count > 0);
        }
 public void Start()
 {
     Server.StartTick();
 }