private void InitializeNewBroadcastersForAllLocalNetworks()
        {
            RemoveAllBroadcasters();

            foreach (var localAddress in NetworkUtilities.GetAllLocalNetworkAddressesOfThisDevice())
            {
                if (BoundBroadcaster.TryCreate(localAddress, Port, out var broadcaster))
                {
                    AllBroadcasters.Add(broadcaster);
                }
            }
        }
Пример #2
0
        public static bool TryCreate(IPAddress localAddress, int port, out BoundBroadcaster broadcaster)
        {
            if (localAddress.AddressFamily != AddressFamily.InterNetwork)
            {
                broadcaster = null;
                return(false);
            }

            try
            {
                broadcaster = new BoundBroadcaster(localAddress, port);
                return(true);
            }
            catch (SocketException)
            {
                broadcaster = null;
                return(false);
            }
        }