/// <summary> /// Start the UdpDiscovery process /// </summary> /// <param name="messageContext">The <see cref="IServiceMessageContext"/> object that should be used in encode/decode messages</param> /// <returns></returns> public virtual async Task StartAsync(IServiceMessageContext messageContext) { await Task.Run(() => { lock (m_lock) { MessageContext = messageContext; // initialize Discovery channels m_discoveryUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Discovery, DiscoveryNetworkInterfaceName, DiscoveryNetworkAddressEndPoint); } }).ConfigureAwait(false); }
/// <summary> /// Perform specific Start tasks /// </summary> protected override Task InternalStart() { lock (m_lock) { //cleanup all existing UdpClient previously open InternalStop(); NetworkAddressUrlDataType networkAddressUrlState = ExtensionObject.ToEncodeable(PubSubConnectionConfiguration.Address) as NetworkAddressUrlDataType; if (networkAddressUrlState == null) { Utils.Trace(Utils.TraceMasks.Error, "The configuration for connection {0} has invalid Address configuration.", this.PubSubConnectionConfiguration.Name); return(Task.FromResult <object>(null)); } NetworkInterfaceName = networkAddressUrlState.NetworkInterface; NetworkAddressEndPoint = UdpClientCreator.GetEndPoint(networkAddressUrlState.Url); if (NetworkAddressEndPoint == null) { Utils.Trace(Utils.TraceMasks.Error, "The configuration for connection {0} with Url:'{1}' resulted in an invalid endpoint.", this.PubSubConnectionConfiguration.Name, networkAddressUrlState.Url); return(Task.FromResult <object>(null)); } //publisher initialization if (Publishers.Count > 0) { m_publisherUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Publisher, networkAddressUrlState, NetworkAddressEndPoint); } //subscriber initialization if (GetAllDataSetReaders().Count > 0) { m_subscriberUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Subscriber, networkAddressUrlState, NetworkAddressEndPoint); foreach (UdpClient subscriberUdpClient in m_subscriberUdpClients) { try { subscriberUdpClient.BeginReceive(new AsyncCallback(OnUadpReceive), subscriberUdpClient); } catch (Exception ex) { Utils.Trace(Utils.TraceMasks.Information, "UdpClient '{0}' Cannot receive data. Exception: {1}", subscriberUdpClient.Client.LocalEndPoint, ex.Message); } } } } return(Task.FromResult <object>(null)); }
/// <summary> /// Perform specific Start tasks /// </summary> protected override async Task InternalStart() { //cleanup all existing UdpClient previously open await InternalStop(); if (NetworkAddressEndPoint == null) { return; } //publisher initialization if (Publishers.Count > 0) { lock (m_lock) { m_publisherUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Publisher, NetworkInterfaceName, NetworkAddressEndPoint); } m_udpDiscoveryPublisher = new UdpDiscoveryPublisher(this); await m_udpDiscoveryPublisher.StartAsync(MessageContext); } //subscriber initialization if (GetAllDataSetReaders().Count > 0) { lock (m_lock) { m_subscriberUdpClients = UdpClientCreator.GetUdpClients(UsedInContext.Subscriber, NetworkInterfaceName, NetworkAddressEndPoint); foreach (UdpClient subscriberUdpClient in m_subscriberUdpClients) { try { subscriberUdpClient.BeginReceive(new AsyncCallback(OnUadpReceive), subscriberUdpClient); } catch (Exception ex) { Utils.Trace(Utils.TraceMasks.Information, "UdpClient '{0}' Cannot receive data. Exception: {1}", subscriberUdpClient.Client.LocalEndPoint, ex.Message); } } } // initialize the discovery channel m_udpDiscoverySubscriber = new UdpDiscoverySubscriber(this); await m_udpDiscoverySubscriber.StartAsync(MessageContext); // add handler to metaDataReceived event this.Application.MetaDataReceived += Application_MetaDataReceived; } }