public static void UseUdpDiscovery(this IAppBuilder app) { var context = new OwinContext(app.Properties); var hostAddresses = context.Get <IList <IDictionary <string, object> > >("host.Addresses"); var addresses = new AddressCollection(hostAddresses); var cancel = context.Get <CancellationToken>("host.OnAppDisposing"); var uris = addresses .Where(a => !string.IsNullOrEmpty(a.Port)) .Select(a => new UriBuilder(a.Scheme, a.Host, int.Parse(a.Port), a.Path).ToString()) .ToList(); RunDiscoveryListener(uris, cancel).ContinueWith(t => { if (t.Exception != null) { Trace.WriteLine("There were problems with discovery: " + t.Exception.ToString()); } }); }