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 <QTimer>
|
||||
#include <QCoreApplication>
|
||||
|
||||
ApismTcpClient::ApismTcpClient(const QString & hostname,
|
||||
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();
|
||||
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)
|
||||
@ -76,17 +82,16 @@ bool ApismTcpClient::isConnected()
|
||||
|
||||
|
||||
|
||||
void ApismTcpClient::sendData(const QByteArray & message)
|
||||
{
|
||||
//qCritical() << "ApismTcpClient::send: " << message;
|
||||
void ApismTcpClient::sendData(const QByteArray & message) {
|
||||
qDebug() << "ApismTcpClient::send: " << message;
|
||||
|
||||
this->sendQueue.enqueue(message);
|
||||
|
||||
if (this->isConnected()) {
|
||||
qCritical() << "ApismTcpClient::send: connected, send" << message;
|
||||
this->private_sendData();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
qCritical() << "ApismTcpClient::send: not connected, connect";
|
||||
this->connectToHost();
|
||||
}
|
||||
}
|
||||
@ -101,7 +106,7 @@ void ApismTcpClient::private_sendData()
|
||||
// take message from queue
|
||||
QByteArray ba = this->sendQueue.dequeue();
|
||||
|
||||
qCritical() << "ApismTcpClient::send: " << QString(ba);
|
||||
qDebug() << "ApismTcpClient::send: " << QString(ba);
|
||||
|
||||
socket->write(ba);
|
||||
socket->flush();
|
||||
@ -112,7 +117,7 @@ void ApismTcpClient::private_sendData()
|
||||
|
||||
void ApismTcpClient::onSocketConnected()
|
||||
{
|
||||
qCritical() << "ApismTcpClient: Connected!";
|
||||
qInfo() << "ApismTcpClient: Connected!";
|
||||
|
||||
if (this->sendQueue.size() > 0) {
|
||||
this->private_sendData();
|
||||
@ -121,8 +126,8 @@ void ApismTcpClient::onSocketConnected()
|
||||
|
||||
void ApismTcpClient::onSocketDisconnected()
|
||||
{
|
||||
qCritical() << "ApismTcpClient: Disconnected!";
|
||||
qCritical() << " -> SocketErrorString: " << socket->errorString();
|
||||
qDebug() << "ApismTcpClient: Disconnected!";
|
||||
qDebug() << " -> SocketErrorString: " << socket->errorString();
|
||||
|
||||
if (this->sendQueue.size() > 0) {
|
||||
this->connectToHost();
|
||||
@ -143,9 +148,10 @@ void ApismTcpClient::onSocketReadyRead()
|
||||
|
||||
readData = socket->readAll();
|
||||
|
||||
qCritical() << "ISMAS received: " << QString(readData);
|
||||
qDebug() << "ISMAS received: " << QString(readData);
|
||||
|
||||
emit this->receivedData(readData);
|
||||
//QCoreApplication::processEvents();
|
||||
|
||||
this->socket->close();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user