Example #1
0
        public void FindDeviceAround()
        {
            try
            {
                Message       MsgSent      = new Message();
                List <Device> devicesFound = new List <Device>();
                while (true)
                {
                    devicesFound.Clear();
                    MsgSent.Pin        = Utils.GeneratePin();
                    MsgSent.DeviceName = Utils.GetDeviceName();
                    UdpMulticastSend(MsgSent);

                    CallWithTimeout(() =>
                    {
                        while (true)
                        {
                            WaitMessage(
                                (msg) => msg.Type == MsgType.Info && msg.Pin == MsgSent.Pin,
                                (remote, msg) => devicesFound.Add(new Device {
                                Addr = remote.Address.ToString(), Name = msg.DeviceName
                            }));
                        }
                    }, 3000);
                    OnDeviceFound?.Invoke(devicesFound);
                }
            }
            catch (OperationCanceledException)
            {
            }
        }
Example #2
0
        //CancellationTokenSource backgroundWorkHandler;


        public async void StartAnnouncing()
        {
            Message announcement = new Message {
                DeviceName = Utils.GetDeviceName(), Pin = 100000
            };
            await Task.Run(() =>
            {
                while (true)
                {
                    UdpMulticastSend(announcement);
                    Thread.Sleep(2000);
                }
            }).ConfigureAwait(false);
        }