PDA

View Full Version : QSslSocket readyRead() signal problem



JaroMast
4th July 2012, 09:02
Hi all,
I'm writing a client application and ofc I need to read data from server.
When I get signal readyRead() i just read data.
The problem apears when serwer sends larger data.
Larger means 128bytes + header (6bytes).
In that case the signal "readyRead()" doesnt occure.
Additionaly after sending another data after this larger data, still signal doesnt show, when at start everything works great.
I also tryid with setting size of ReadBuffer manual but this doesnt help.
Did someone have problem like that or know how to make it work with larger data?
I tested it with 2 server: (1st in java, 2nd in qt), on both there is the same problem. So i think it must be client server.

fakhredin
19th February 2013, 13:05
Hi Dear
use this code:

class APHTTP : public QHttp
{
Q_OBJECT

rivate:
QString mHost;
QHttpRequestHeader mHeader;
QSslSocket socket;

public slots:
void findPageGet();
void socketReadyRead();
void socketEncrypted();
void sslErrors(QList<QSslError>);
void socketStateChanged(QAbstractSocket::SocketState);
}

APHTTP::APHTTP()
{
mHost = "localhost";
connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)) ,
this, SLOT(socketStateChanged(QAbstractSocket::SocketSta te)));
connect(&socket, SIGNAL(encrypted()),
this, SLOT(socketEncrypted()));
connect(&socket, SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(sslErrors(QList<QSslError>)));
connect(&socket, SIGNAL(readyRead()),
this, SLOT(socketReadyRead()));

socket.connectToHostEncrypted(mHost, 443, QIODevice::ReadWrite);
socket.waitForConnected();
socket.startClientEncryption();
if (!socket.waitForEncrypted())
{
qDebug() << socket.errorString();
return ;
}
this->setSocket(&socket);
connect(this, SIGNAL(done(bool)), this, SLOT(findPageGet()));
// you should set header!!!!!!!!!
this->setHost(mHost, QHttp::ConnectionModeHttp);
this->request(mHeader);
}

void APHTTP::findPageGet()
{
QByteArray bytData;
QMutex mutex;
QString body;

bytData = this->readAll();
body = QString::QString(bytData);
this->deleteLater();
}

void APHTTP::socketReadyRead()
{
QString str;

str = QString::fromUtf8(socket.readAll());
}

void APHTTP::sslErrors( QList<QSslError> error)
{
}

void APHTTP::socketEncrypted()
{
}

void APHTTP::socketStateChanged( QAbstractSocket::SocketState state )
{
}

anda_skoa
19th February 2013, 18:39
I would suggest to use QNetworkAccessManager instead of QHttp. The latter is deprecated and the former can handle SSL itself.

Cheers,
_