Now using parseHostAddress from dbnetworklib
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
QT += core network serialport
|
QT += core network serialport
|
||||||
QT -= gui widgets
|
QT -= gui widgets
|
||||||
|
|
||||||
DBLIBS +=
|
DBLIBS += dbnetwork
|
||||||
|
|
||||||
TARGET = serialserver
|
TARGET = serialserver
|
||||||
|
|
||||||
|
33
main.cpp
33
main.cpp
@@ -4,6 +4,8 @@
|
|||||||
#include <QSerialPort>
|
#include <QSerialPort>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
|
|
||||||
|
#include "utils/netutils.h"
|
||||||
|
|
||||||
#include "master.h"
|
#include "master.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -30,33 +32,12 @@ int main(int argc, char *argv[])
|
|||||||
qDebug() << "Starting tcp server...";
|
qDebug() << "Starting tcp server...";
|
||||||
auto server = new QTcpServer;
|
auto server = new QTcpServer;
|
||||||
|
|
||||||
|
if(!server->listen(parseHostAddress(settings.value("server/address", "Any").toString()),
|
||||||
|
(quint16)settings.value("server/port", 1234).toUInt()))
|
||||||
{
|
{
|
||||||
auto listenAddress = settings.value("server/address", "Any").toString();
|
qWarning() << server->errorString();
|
||||||
QHostAddress hostAddress;
|
qFatal("could not start listening");
|
||||||
|
return -2;
|
||||||
if(listenAddress == "Null")
|
|
||||||
hostAddress = QHostAddress::Null;
|
|
||||||
else if(listenAddress == "Broadcast")
|
|
||||||
hostAddress = QHostAddress::Broadcast;
|
|
||||||
else if(listenAddress == "LocalHost")
|
|
||||||
hostAddress = QHostAddress::LocalHost;
|
|
||||||
else if(listenAddress == "LocalHostIPv6")
|
|
||||||
hostAddress = QHostAddress::LocalHostIPv6;
|
|
||||||
else if(listenAddress == "Any")
|
|
||||||
hostAddress = QHostAddress::Any;
|
|
||||||
else if(listenAddress == "AnyIPv6")
|
|
||||||
hostAddress = QHostAddress::AnyIPv6;
|
|
||||||
else if(listenAddress == "AnyIPv4")
|
|
||||||
hostAddress = QHostAddress::AnyIPv4;
|
|
||||||
else
|
|
||||||
hostAddress = QHostAddress(listenAddress);
|
|
||||||
|
|
||||||
if(!server->listen(hostAddress, (quint16)settings.value("server/port", 1234).toUInt()))
|
|
||||||
{
|
|
||||||
qWarning() << server->errorString();
|
|
||||||
qFatal("could not start listening");
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new Master(serialPort, server, &app);
|
new Master(serialPort, server, &app);
|
||||||
|
@@ -3,5 +3,5 @@ port = COM3
|
|||||||
baudrate = 9600
|
baudrate = 9600
|
||||||
|
|
||||||
[server]
|
[server]
|
||||||
address = Any
|
address = QHostAddress::Any
|
||||||
port = 1234
|
port = 1234
|
||||||
|
Reference in New Issue
Block a user