Added call to waitForConnected() when doing a connectToHost().
Replaced some qCritical() with qDebug()-calls.
This commit is contained in:
parent
cd1c92a7db
commit
92084bed99
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
ApismTcpClient::ApismTcpClient(const QString & hostname,
|
ApismTcpClient::ApismTcpClient(const QString & hostname,
|
||||||
const QString & port,
|
const QString & port,
|
||||||
@ -26,10 +27,15 @@ ApismTcpClient::ApismTcpClient(const QString & hostname,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ApismTcpClient::connectToHost()
|
void ApismTcpClient::connectToHost() {
|
||||||
{
|
qCritical() << "ApismTcpClient::connectToHost(this->" << hostname << ", " << port << ")";
|
||||||
int portNumber = this->port.toInt();
|
int portNumber = this->port.toInt();
|
||||||
this->socket->connectToHost(QHostAddress(this->hostname), portNumber);
|
this->socket->connectToHost(QHostAddress(this->hostname), portNumber);
|
||||||
|
if (!socket->waitForConnected(10000)) {
|
||||||
|
qCritical() << "ERROR IN WAIT FOR CONNECTED" << socket->errorString();
|
||||||
|
} else {
|
||||||
|
qDebug() << "connected to" << hostname << ", " << port << ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApismTcpClient::connectToHost(const QString & hostname, const QString & port)
|
void ApismTcpClient::connectToHost(const QString & hostname, const QString & port)
|
||||||
@ -76,17 +82,16 @@ bool ApismTcpClient::isConnected()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ApismTcpClient::sendData(const QByteArray & message)
|
void ApismTcpClient::sendData(const QByteArray & message) {
|
||||||
{
|
qDebug() << "ApismTcpClient::send: " << message;
|
||||||
//qCritical() << "ApismTcpClient::send: " << message;
|
|
||||||
|
|
||||||
this->sendQueue.enqueue(message);
|
this->sendQueue.enqueue(message);
|
||||||
|
|
||||||
if (this->isConnected()) {
|
if (this->isConnected()) {
|
||||||
|
qCritical() << "ApismTcpClient::send: connected, send" << message;
|
||||||
this->private_sendData();
|
this->private_sendData();
|
||||||
|
} else {
|
||||||
}
|
qCritical() << "ApismTcpClient::send: not connected, connect";
|
||||||
else {
|
|
||||||
this->connectToHost();
|
this->connectToHost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +106,7 @@ void ApismTcpClient::private_sendData()
|
|||||||
// take message from queue
|
// take message from queue
|
||||||
QByteArray ba = this->sendQueue.dequeue();
|
QByteArray ba = this->sendQueue.dequeue();
|
||||||
|
|
||||||
qCritical() << "ApismTcpClient::send: " << QString(ba);
|
qDebug() << "ApismTcpClient::send: " << QString(ba);
|
||||||
|
|
||||||
socket->write(ba);
|
socket->write(ba);
|
||||||
socket->flush();
|
socket->flush();
|
||||||
@ -112,7 +117,7 @@ void ApismTcpClient::private_sendData()
|
|||||||
|
|
||||||
void ApismTcpClient::onSocketConnected()
|
void ApismTcpClient::onSocketConnected()
|
||||||
{
|
{
|
||||||
qCritical() << "ApismTcpClient: Connected!";
|
qInfo() << "ApismTcpClient: Connected!";
|
||||||
|
|
||||||
if (this->sendQueue.size() > 0) {
|
if (this->sendQueue.size() > 0) {
|
||||||
this->private_sendData();
|
this->private_sendData();
|
||||||
@ -121,8 +126,8 @@ void ApismTcpClient::onSocketConnected()
|
|||||||
|
|
||||||
void ApismTcpClient::onSocketDisconnected()
|
void ApismTcpClient::onSocketDisconnected()
|
||||||
{
|
{
|
||||||
qCritical() << "ApismTcpClient: Disconnected!";
|
qDebug() << "ApismTcpClient: Disconnected!";
|
||||||
qCritical() << " -> SocketErrorString: " << socket->errorString();
|
qDebug() << " -> SocketErrorString: " << socket->errorString();
|
||||||
|
|
||||||
if (this->sendQueue.size() > 0) {
|
if (this->sendQueue.size() > 0) {
|
||||||
this->connectToHost();
|
this->connectToHost();
|
||||||
@ -143,9 +148,10 @@ void ApismTcpClient::onSocketReadyRead()
|
|||||||
|
|
||||||
readData = socket->readAll();
|
readData = socket->readAll();
|
||||||
|
|
||||||
qCritical() << "ISMAS received: " << QString(readData);
|
qDebug() << "ISMAS received: " << QString(readData);
|
||||||
|
|
||||||
emit this->receivedData(readData);
|
emit this->receivedData(readData);
|
||||||
|
//QCoreApplication::processEvents();
|
||||||
|
|
||||||
this->socket->close();
|
this->socket->close();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user