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); }
public void Dispose() { #if (NETSTANDARD1_5) BackingUdpClient?.Dispose(); #else BackingUdpClient?.Close(); #endif }
public void Disconnect() { MessageConcellationTokenSource.Cancel(); BackingUdpClient.Close(); _multicastAddress = null; _multicastPort = 0; }
public void Dispose() { _cancellationTokenSource?.Cancel(); #if (NETSTANDARD1_5 || NETSTANDARD1_3) BackingUdpClient?.Dispose(); #else BackingUdpClient?.Close(); #endif _messageSubject?.OnCompleted(); }
protected override void Cleanup() { _cancellationTokenSource.Cancel(); #if (NETSTANDARD1_5 || NETSTANDARD1_3) BackingUdpClient.Dispose(); #else BackingUdpClient.Close(); #endif base.Cleanup(); }
protected override void Cleanup() { _cancellationTokenSource.Cancel(); MulticastMemberships.Clear(); #if (NETSTANDARD1_5 || NETSTANDARD1_3) BackingUdpClient?.Dispose(); #else BackingUdpClient?.Close(); #endif _multicastAddress = null; _multicastPort = 0; base.Cleanup(); }
public void MulticastDropMembership(string ipLan, string mcastAddress) { if (!IsMulticastActive) { throw new ArgumentException("Multicast interface must be initialized before dropping multicast memberships"); } if (!MulticastMemberships.ContainsKey(mcastAddress)) { return; } BackingUdpClient.DropMulticastGroup(IPAddress.Parse(mcastAddress)); MulticastMemberships.Remove(mcastAddress); }
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); }
public async Task ConnectAsync( string address, int port, bool allowMultipleBindToSamePort = false) { if (allowMultipleBindToSamePort) { BackingUdpClient.ExclusiveAddressUse = false; BackingUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); } else { BackingUdpClient.ExclusiveAddressUse = true; BackingUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, false); } MessageConcellationTokenSource = new CancellationTokenSource(); await Task.Run(() => BackingUdpClient.Connect(address, port), MessageConcellationTokenSource.Token) .WrapNativeSocketExceptions() .ConfigureAwait(false); }
public void Dispose() { BackingUdpClient?.Close(); }
public void Disconnect() { MessageConcellationTokenSource?.Cancel(); BackingUdpClient?.Close(); }
public void Dispose() { MessageConcellationTokenSource?.Cancel(); BackingUdpClient?.Close(); MessageSubject?.OnCompleted(); }
public void StopListening() { MessageConcellationTokenSource.Cancel(); BackingUdpClient.Close(); }