Resolve host address via dns
This commit is contained in:
parent
5040a79a93
commit
49e1aa98bf
2 changed files with 8 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include<QJsonObject>
|
||||
#include<QJsonArray>
|
||||
#include<QMessageBox>
|
||||
#include<QHostInfo>
|
||||
|
||||
#include "mqttclient.h"
|
||||
#include "items/mqttitem.h"
|
||||
|
|
@ -169,7 +170,7 @@ SecondaryMainObject::SecondaryMainObject(QString host, int port, QObject *parent
|
|||
globalItems.registerItemSource(tcpClient);
|
||||
connect(&globalSensors, &SensorStore::sensorChangedState, tcpClient, &TcpClient::sensorEvent);
|
||||
|
||||
if(!tcpClient->launch(QHostAddress(host), port))
|
||||
if(!tcpClient->launch(QHostInfo::fromName(host).addresses()[0], port))
|
||||
{
|
||||
QMessageBox::critical(nullptr, "Error", "Could not connect to "+host+":"+QString::number(port));
|
||||
QMetaObject::invokeMethod(this, [](){exit(1);}, Qt::QueuedConnection);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,12 @@ void TcpClient::sendJson(const QJsonObject& json)
|
|||
bool TcpClient::launch(const QHostAddress &address, quint16 port)
|
||||
{
|
||||
socket->connectToHost(address, port);
|
||||
return socket->waitForConnected(2000);
|
||||
if(!socket->waitForConnected(4000))
|
||||
{
|
||||
qWarning()<<"Unable to connect to "<<address<<':'<<port<<' '<<socket->error();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TcpClient::processIncomeingJson(const QByteArray& jsonbytes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue