Vector receivers = findReceivers((Vector)scopesToUse.clone()); if(!receivers.isEmpty()) { DAInfo da; Iterator iter = receivers.iterator(); SLPMessageSender ms = new SLPMessageSender(this, CONFIG_SLP_MTU, CONFIG_RETRY, results); Vector additional = null; while(iter.hasNext() || additional != null) { if(!iter.hasNext()) { receivers = additional; iter = receivers.iterator(); additional = null; } da = (DAInfo)iter.next();  if(da.getHost().equals(CONFIG_SLP_MC_ADDR)) {  req.setFlags(SLPMessageHeader.FLAG_MCAST); ms.sendSLPMessage(req,  da.getHost(), da.getPort(), CONFIG_MC_MAX, unicastCommunicator); } else {     try { ms.sendSLPMessage(req,  da.getHost(), da.getPort(), CONFIG_RETRY_MAX, unicastCommunicator); }catch(ServiceLocationException se) { if(se.getErrorCode() == ServiceLocationException.DA_NOT_AVAILABLE) { DAs.remove(da.getHost());      additional = findReceivers(da.getScopes()); for(Iterator it = additional.iterator(); it.hasNext(); ) { if(receivers.contains(it.next())) { it.remove(); } } } else {  throw se; } } } } } else { throw new ServiceLocationException(ServiceLocationException.SCOPE_NOT_SUPPORTED, "UA: Requested scope is NOT supported"); }
sendRequest(req, scopesToUse, results);
    public ServiceLocationEnumeration findServices(                                                   ServiceType type,                                                   Vector scopes,                                                   String filter)    throws ServiceLocationException {        ServiceLocationEnumeration results = new ServiceURLEnumeration();                // check that the UA supports the scopes given.        Vector scopesToUse = getSupportedScopes(scopes);        if(scopesToUse.isEmpty()) {            throw new ServiceLocationException(ServiceLocationException.SCOPE_NOT_SUPPORTED,                                               "UA: Requested scope is NOT supported");        }        SLPSrvReqMessage req = new SLPSrvReqMessage(type, scopesToUse, filter, locale);                Vector receivers = findReceivers((Vector)scopesToUse.clone());        if(!receivers.isEmpty()) {            DAInfo da;            Iterator iter = receivers.iterator();            SLPMessageSender ms = new SLPMessageSender(this, CONFIG_SLP_MTU, CONFIG_RETRY, results);            Vector additional = null;            while(iter.hasNext() || additional != null) {                if(!iter.hasNext()) {                    receivers = additional;                    iter = receivers.iterator();                    additional = null;                }                da = (DAInfo)iter.next();                                if(da.getHost().equals(CONFIG_SLP_MC_ADDR)) {                    //System.out.println("UserAgent -> Sending multicast");                    req.setFlags(SLPMessageHeader.FLAG_MCAST);                    ms.sendSLPMessage(req,                                       //address, CONFIG_SLP_AGENTPORT,                                      da.getHost(), da.getPort(), CONFIG_MC_MAX,                                      unicastCommunicator);                }                else {                    //System.out.println("UserAgent -> Sending to DA");                    // If the DA is down, we should try to find another DA supporting                    // the wanted scopes, or in the worst case use multicast...                    // Currently the we go directly do multicast if a DA is down                    try {                        ms.sendSLPMessage(req,                                           //address, CONFIG_SLP_AGENTPORT,                                          da.getHost(), da.getPort(), CONFIG_RETRY_MAX,                                          unicastCommunicator);                    }catch(ServiceLocationException se) {                        if(se.getErrorCode() == ServiceLocationException.DA_NOT_AVAILABLE) {                            DAs.remove(da.getHost());                            // do multicast...                            // Should try to find another DA before going multicast...                            /*                            DAInfo mc = new DAInfo(CONFIG_SLP_MC_ADDR, CONFIG_SLP_PORT);                            if(!receivers.contains(mc)) {                                additional = mc;                            }                             */                                                        // find another DA (or DAs)...                            additional = findReceivers(da.getScopes());                            for(Iterator it = additional.iterator(); it.hasNext(); ) {                                if(receivers.contains(it.next())) {                                    it.remove();                                }                            }                        }                        else {                            // some other exception.                            throw se;                        }                    }                }            }        }        else {            throw new ServiceLocationException(ServiceLocationException.SCOPE_NOT_SUPPORTED,                                               "UA: Requested scope is NOT supported");        }                    // return the discovered service URLs        return results;    }