diff --git a/MediaBrowser.Dlna/Ssdp/DeviceDiscovery.cs b/MediaBrowser.Dlna/Ssdp/DeviceDiscovery.cs index a2eac41ec3..5e0baa1f67 100644 --- a/MediaBrowser.Dlna/Ssdp/DeviceDiscovery.cs +++ b/MediaBrowser.Dlna/Ssdp/DeviceDiscovery.cs @@ -109,30 +109,31 @@ namespace MediaBrowser.Dlna.Ssdp var endPoint = new IPEndPoint(localIp, 1900); - var socket = GetMulticastSocket(localIp, endPoint); - - var receiveBuffer = new byte[64000]; - - CreateNotifier(localIp); - - while (!_tokenSource.IsCancellationRequested) + using (var socket = GetMulticastSocket(localIp, endPoint)) { - var receivedBytes = await socket.ReceiveAsync(receiveBuffer, 0, 64000); + var receiveBuffer = new byte[64000]; + + CreateNotifier(localIp); - if (receivedBytes > 0) + while (!_tokenSource.IsCancellationRequested) { - var args = SsdpHelper.ParseSsdpResponse(receiveBuffer); - args.EndPoint = endPoint; - args.LocalEndPoint = new IPEndPoint(localIp, 0); + var receivedBytes = await socket.ReceiveAsync(receiveBuffer, 0, 64000); - if (_ssdpHandler.IgnoreMessage(args, true)) + if (receivedBytes > 0) { - return; - } + var args = SsdpHelper.ParseSsdpResponse(receiveBuffer); + args.EndPoint = endPoint; + args.LocalEndPoint = new IPEndPoint(localIp, 0); + + if (_ssdpHandler.IgnoreMessage(args, true)) + { + return; + } - _ssdpHandler.LogMessageReceived(args, true); + _ssdpHandler.LogMessageReceived(args, true); - TryCreateDevice(args); + TryCreateDevice(args); + } } }