public void StartAnnouncing()
{
Task.Factory.StartNew(() =>
{
try
{
CancellationToken token = cts.Token;
logger.Trace("Start announcing");
using (var client = new UdpClient())
{
var ip = new IPEndPoint(IPAddress.Broadcast, 15000);
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
while (true)
{
token.ThrowIfCancellationRequested();
byte[] bytes = Encoding.ASCII.GetBytes("MonoServer");
client.Send(bytes, bytes.Length, ip);
Thread.Sleep(100);
}
}
}
catch (OperationCanceledException)
{
}
catch (Exception ex)
{
logger.Trace(ex);
}
});
}