private void sendToRemoteServer(String domain, String multicastService) {
        Collection<Packet> packets = null;
        // Get the packets to send to the remote entity
        synchronized (domainMutex.intern(new JID(null, domain, null))) {
            packets = remotePackets.remove(domain);
        }

        if (multicastService != null && !multicastService.trim().isEmpty()) {
            // Remote server has a multicast service so send pending packets to the
            // multicast service
            for (Packet packet : packets) {
                Element addresses = getAddresses(packet);
                for (Iterator<Element> it=addresses.elementIterator("address");it.hasNext();) {
                    Element address = it.next();
                    String jid = address.attributeValue("jid");
                    if (!jid.contains("@"+domain)) {
                        if (Type.bcc.toString().equals(address.attributeValue("type"))) {
                            it.remove();
                        }
                        else {
                            address.addAttribute("delivered", "true");
                        }
                    }
                }
                // Set that the target of the packet is the multicast service
                packet.setTo(multicastService);
                // Send the packet to the remote entity
                packetRouter.route(packet);
            }
        }
        else {
            // Remote server does not have a multicast service so send pending packets
            // to each address
            for (Packet packet : packets) {
                Element addresses = getAddresses(packet);
                List<String> targets = new ArrayList<>();

                for (Iterator<Element> it=addresses.elementIterator("address");it.hasNext();) {
                    Element address = it.next();
                    String jid = address.attributeValue("jid");
                    // Keep a list of the remote users that are going to receive the packet
                    if (jid.contains("@"+domain)) {
                        targets.add(jid);
                    }
                    // Set as delivered
                    address.addAttribute("delivered", "true");
                    // Remove bcc addresses
                    if (Type.bcc.toString().equals(address.attributeValue("type"))) {
                        it.remove();
                    }
                }

                // Send the packet to each remote user
                for (String jid : targets) {
                    packet.setTo(jid);
                    packetRouter.route(packet);
                }
            }
        }
    }
Actually sends pending packets of the specified domain using the discovered multicast
service address. If remote server supports multicast service then a copy of the
orignal will be sent to the remote server. However, if no multicast service was found
then the local server sends a copy of the original stanza to each address.

@param domain domain of the remote server with pending packets.
@param multicastService address of the discovered multicast service.
xmppserver/src/main/java/org/jivesoftware/openfire/MulticastRouter.java