From 6cb63e7e30906f428c601ba00fd15c14e07093cf Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Mon, 25 Aug 2014 18:08:15 +0200 Subject: Client is able to auto - connect to the same room belonging manager. --- src/client/net/serverdiscovery.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/client/net/serverdiscovery.cpp') diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp index a4edb46..2cd0796 100644 --- a/src/client/net/serverdiscovery.cpp +++ b/src/client/net/serverdiscovery.cpp @@ -45,8 +45,14 @@ ServerDiscovery::~ServerDiscovery() /***************************************************************************//** * @brief start */ -void ServerDiscovery::start(const QByteArray& sessionName) +void ServerDiscovery::start(const QByteArray& sessionName, QString mgrIP) { + if (mgrIP != NULL) { + _mgrIP.setAddress(mgrIP); + } else { + _mgrIP = NULL; + } + //assert(!this->isActive()); // Set the session which is searched @@ -98,21 +104,31 @@ void ServerDiscovery::doDiscovery() _packet.setField(_SALT1, salt1); _packet.setField(_SALT2, _salt2); _packet.setField(_IPLIST, iplist); - foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) + + // Check if specifig manager IP is given. If not broadcast in whole network. + if (_mgrIP != QHostAddress::Null) + { + qDebug() << "Broadcasting to " << _mgrIP.toString(); + if (!_packet.writeMessage(&_discoverySocket, _mgrIP, SERVICE_DISCOVERY_PORT)) + qDebug("Failed"); + } else { - foreach (QNetworkAddressEntry entry, interface.addressEntries()) + foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) { - if (!entry.broadcast().isNull() && entry.ip() != QHostAddress::LocalHost && entry.ip() != QHostAddress::LocalHostIPv6) + foreach (QNetworkAddressEntry entry, interface.addressEntries()) { - qDebug() << "Broadcasting to " << entry.broadcast().toString(); - if (!_packet.writeMessage(&_discoverySocket, entry.broadcast(), SERVICE_DISCOVERY_PORT)) - qDebug("FAILED"); + if (!entry.broadcast().isNull() && entry.ip() != QHostAddress::LocalHost && entry.ip() != QHostAddress::LocalHostIPv6) + { + qDebug() << "Broadcasting to " << entry.broadcast().toString(); + if (!_packet.writeMessage(&_discoverySocket, entry.broadcast(), SERVICE_DISCOVERY_PORT)) + qDebug("FAILED"); + } } } + qDebug("Broadcasting to 255.255.255.255"); + if (!_packet.writeMessage(&_discoverySocket, QHostAddress::Broadcast, SERVICE_DISCOVERY_PORT)) + qDebug("FAILED"); } - qDebug("Broadcasting to 255.255.255.255"); - if (!_packet.writeMessage(&_discoverySocket, QHostAddress::Broadcast, SERVICE_DISCOVERY_PORT)) - qDebug("FAILED"); // Start the timer again with a larger interval if (_discoveryTimer.interval() < 5000) -- cgit v1.2.3-55-g7522