public async Task JoinMulticastGroupAsync( string multicastAddress, int port, ICommunicationInterface communicationInterface = null, bool allowMultipleBindToSamePort = false) { CheckCommunicationInterface(communicationInterface); var ipAddress = (communicationInterface as CommunicationInterface)?.NativeIpAddress ?? IPAddress.Any; var ipEndPoint = new IPEndPoint(ipAddress, port); InitializeUdpClient(ipEndPoint, allowMultipleBindToSamePort); MessageConcellationTokenSource = new CancellationTokenSource(); var multicastIp = IPAddress.Parse(multicastAddress); try { BackingUdpClient.JoinMulticastGroup(multicastIp, TTL); } catch (Exception ex) { throw (NativeSocketExceptions.Contains(ex.GetType())) ? new PclSocketException(ex) : ex; } _multicastAddress = multicastAddress; _multicastPort = port; await Task.Run(() => RunMessageReceiver(MessageConcellationTokenSource.Token)).ConfigureAwait(false); }
protected void MulticastAddMembership(IPAddress ipAddress, IPAddress mcastAddress) { if (!IsMulticastActive) { throw new ArgumentException("Multicast interface must be initialized before adding multicast memberships"); } if (MulticastMemberships.ContainsKey(mcastAddress.ToString())) { if (MulticastMemberships[mcastAddress.ToString()].Equals(true)) { // The membership has already been added - do nothing return; } } BackingUdpClient.JoinMulticastGroup(mcastAddress, ipAddress); MulticastMemberships.Add(mcastAddress.ToString(), true); }