17 #include <QNetworkInterface>
21 if (address.protocol() == QAbstractSocket::IPv4Protocol) {
22 return address.isInSubnet(QHostAddress(QLatin1String(
"224.0.0.0")), 4);
23 }
else if (address.protocol() == QAbstractSocket::IPv6Protocol) {
24 return address.isInSubnet(QHostAddress(QLatin1String(
"ff00::")), 8);
34 d->socket =
new QUdpSocket(
this);
46 const bool rc = d->socket->bind(QHostAddress::Any, port, mode);
48 qWarning() <<
"KDSoapUdpClient: failed to bind on port" << port <<
"mode" << mode <<
":" << d->socket->errorString();
56 d->soapVersion = version;
64 const QByteArray data = msgWriter.
messageToXml(message, QString(), headers, QMap<QString, KDSoapMessage>());
67 bool anySuccess =
false;
68 const auto &allInterfaces = QNetworkInterface::allInterfaces();
69 for (
const auto &iface : allInterfaces) {
70 if (iface.flags().testFlag(QNetworkInterface::IsUp) && iface.flags().testFlag(QNetworkInterface::CanMulticast)) {
72 d->socket->setMulticastInterface(iface);
73 const qint64 writtenSize = d->socket->writeDatagram(data, address, port);
74 anySuccess = anySuccess || (writtenSize == data.size());
80 const qint64 writtenSize = d->socket->writeDatagram(data, address, port);
81 return writtenSize == data.size();
87 QUdpSocket *
socket = qobject_cast<QUdpSocket *>(sender());
88 while (
socket->hasPendingDatagrams()) {
89 qint64 size =
socket->pendingDatagramSize();
93 QHostAddress senderAddress;
95 socket->readDatagram(buffer.data(), buffer.size(), &senderAddress, &senderPort);
112 emit q->receivedMessage(replyMessage, replyHeaders, senderAddress, senderPort);
static bool isMulticastAddress(const QHostAddress &address)
XmlError xmlToMessage(const QByteArray &data, KDSoapMessage *pParsedMessage, QString *pMessageNamespace, KDSoapHeaders *pRequestHeaders, KDSoap::SoapVersion soapVersion) const
QByteArray messageToXml(const KDSoapMessage &message, const QString &method, const KDSoapHeaders &headers, const QMap< QString, KDSoapMessage > &persistentHeaders, const KDSoapAuthentication &authentication=KDSoapAuthentication()) const
void setVersion(KDSoap::SoapVersion version)
KDSoap::SoapVersion soapVersion
void receivedDatagram(const QByteArray &messageData, const QHostAddress &senderAddress, quint16 senderPort)
KDSoapUdpClient provides an interface for implementing a SOAP-over-UDP client.
void setSoapVersion(KDSoap::SoapVersion version)
bool bind(quint16 port=0, QAbstractSocket::BindMode mode=QAbstractSocket::DefaultForPlatform)
bool sendMessage(const KDSoapMessage &message, const KDSoapHeaders &headers, const QHostAddress &address, quint16 port)
KDSoapUdpClient(QObject *parent=nullptr)