Time out if no local units are found in 1 second

This commit is contained in:
2019-02-20 15:08:33 -06:00
parent 3e4084714b
commit 9655b95898

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -28,11 +29,14 @@ namespace ScreenLogicConnect
{ {
await udpClient.SendAsync(broadcastData, broadcastData.Length, new IPEndPoint(IPAddress.Broadcast, multicastPort)); await udpClient.SendAsync(broadcastData, broadcastData.Length, new IPEndPoint(IPAddress.Broadcast, multicastPort));
var buf = await udpClient.ReceiveAsync(); var buf = await udpClient.ReceiveAsync().TimeoutAfter(TimeSpan.FromSeconds(1));
var findServerResponse = new EasyTouchUnit(buf); if (buf != null)
if (findServerResponse.isValid)
{ {
units.Add(findServerResponse); var findServerResponse = new EasyTouchUnit(buf);
if (findServerResponse.isValid)
{
units.Add(findServerResponse);
}
} }
} }