protected override void DoStartAgent()

in src/Transport/Discovery/Multicast/MulticastDiscoveryAgent.cs [109:171]


		protected override void DoStartAgent()
		{
            if (String.IsNullOrEmpty(group)) 
            {
                throw new IOException("You must specify a group to discover");
            }
            String type = Type;
            if (!type.EndsWith(".")) 
            {
                Tracer.Warn("The type '" + type + "' should end with '.' to be a valid Discovery type");
                type += ".";
            }
            
            if (DiscoveryURI == null) 
            {
                DiscoveryURI = new Uri(DEFAULT_DISCOVERY_URI_STRING);
            }

            if (Tracer.IsDebugEnabled) 
            {
                Tracer.Debug("start - discoveryURI = " + DiscoveryURI);                              
            }

            String targetHost = DiscoveryURI.Host;
            int targetPort = DiscoveryURI.Port;
                 
            if (DEFAULT_HOST_STR.Equals(targetHost)) 
            {
                targetHost = DEFAULT_HOST_IP;                     
            }

            if (targetPort < 0) 
            {
                targetPort = DEFAULT_PORT;              
            }
              
            if (Tracer.IsDebugEnabled) 
            {
                Tracer.DebugFormat("start - myHost = {0}", targetHost); 
                Tracer.DebugFormat("start - myPort = {0}", targetPort);    
                Tracer.DebugFormat("start - group  = {0}", group);                    
                Tracer.DebugFormat("start - interface  = {0}", mcInterface);
                Tracer.DebugFormat("start - network interface  = {0}", mcNetworkInterface);
                Tracer.DebugFormat("start - join network interface  = {0}", mcJoinNetworkInterface);
            } 

            int numFailedAttempts = 0;
            int backoffTime = SOCKET_CONNECTION_BACKOFF_TIME;

            Tracer.Info("Connecting to multicast discovery socket.");
            while (!TryToConnectSocket(targetHost, targetPort))
            {
                numFailedAttempts++;
                if (numFailedAttempts > MAX_SOCKET_CONNECTION_RETRY_ATTEMPS)
                {
                    throw new ApplicationException(
                        "Could not open the socket in order to discover advertising brokers.");
                }

                Thread.Sleep(backoffTime);
                backoffTime = (int)(backoffTime * BackOffMultiplier);
            }
		}