|
|
|
@ -8,19 +8,11 @@ NetControl::NetControl(const QString& configPath, bool bAutoReconnect /* = false
|
|
|
|
{
|
|
|
|
{
|
|
|
|
qRegisterMetaType<QAbstractSocket::SocketError>("QAbstractSocket::SocketError");
|
|
|
|
qRegisterMetaType<QAbstractSocket::SocketError>("QAbstractSocket::SocketError");
|
|
|
|
initIpAddress(m_configPath);
|
|
|
|
initIpAddress(m_configPath);
|
|
|
|
m_pTimerHeartbeat = new QTimer(this);
|
|
|
|
|
|
|
|
connect(m_pTimerHeartbeat, &QTimer::timeout, this, &NetControl::sendHeartbeatPack);
|
|
|
|
|
|
|
|
m_pTcpSocket = new QTcpSocket(this);
|
|
|
|
|
|
|
|
connect(m_pTcpSocket, SIGNAL(connected()), this, SLOT(onConnected()));
|
|
|
|
|
|
|
|
connect(m_pTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
|
|
|
|
|
|
|
this, SLOT(onErrorHandler(QAbstractSocket::SocketError)));
|
|
|
|
|
|
|
|
connect(m_pTcpSocket, SIGNAL(readyRead()), this, SLOT(onMsgReceived()));
|
|
|
|
|
|
|
|
connect(m_pTcpSocket, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
|
|
|
|
|
|
|
|
connectNet(m_szHostIp, m_port);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NetControl::~NetControl()
|
|
|
|
NetControl::~NetControl()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
qDebug() << "delete netControl";
|
|
|
|
if (m_pTimerHeartbeat)
|
|
|
|
if (m_pTimerHeartbeat)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_pTimerHeartbeat->stop();
|
|
|
|
m_pTimerHeartbeat->stop();
|
|
|
|
@ -34,6 +26,7 @@ NetControl::~NetControl()
|
|
|
|
m_pTcpSocket->deleteLater();
|
|
|
|
m_pTcpSocket->deleteLater();
|
|
|
|
m_pTcpSocket = nullptr;
|
|
|
|
m_pTcpSocket = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "delete netControl finished";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool NetControl::initIpAddress(const QString& path)
|
|
|
|
bool NetControl::initIpAddress(const QString& path)
|
|
|
|
@ -74,6 +67,19 @@ bool NetControl::initIpAddress(const QString& path)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void NetControl::onInitNet()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_pTimerHeartbeat = new QTimer(this);
|
|
|
|
|
|
|
|
connect(m_pTimerHeartbeat, &QTimer::timeout, this, &NetControl::sendHeartbeatPack);
|
|
|
|
|
|
|
|
m_pTcpSocket = new QTcpSocket(this);
|
|
|
|
|
|
|
|
connect(m_pTcpSocket, SIGNAL(connected()), this, SLOT(onConnected()));
|
|
|
|
|
|
|
|
connect(m_pTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
|
|
|
|
|
|
|
this, SLOT(onErrorHandler(QAbstractSocket::SocketError)));
|
|
|
|
|
|
|
|
connect(m_pTcpSocket, SIGNAL(readyRead()), this, SLOT(onMsgReceived()));
|
|
|
|
|
|
|
|
connect(m_pTcpSocket, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
|
|
|
|
|
|
|
|
connectNet(m_szHostIp, m_port);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NetControl::connectNet(QString severIp, int serverPort)
|
|
|
|
void NetControl::connectNet(QString severIp, int serverPort)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_pTcpSocket->connectToHost(severIp, serverPort);
|
|
|
|
m_pTcpSocket->connectToHost(severIp, serverPort);
|
|
|
|
|