Hi,
I have a very simple client inspired from the fortuneclient. But for some reason, my readFortune never gets called. It connects, no errors but the slot is never called. It's as if it never gets any data.
Using nc I am able to see data streaming from the server. The host and port most definitely exist.
QuarqdClient is of type QObject...
Any ideas ?
Thanks
J
#include <QtNetwork>
#include "QuarqdClient.h"
QuarqdClient::QuarqdClient()
{
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFortune()));
requestNewFortune();
//readFortune();
}
void QuarqdClient::requestNewFortune()
{
blockSize = 0;
tcpSocket->abort();
tcpSocket->connectToHost("192.168.1.2", 8168);
}
void QuarqdClient::readFortune()
{
qDebug() << "Reading!!";
if (blockSize == 0) {
if (tcpSocket->bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
if (tcpSocket->bytesAvailable() < blockSize)
return;
in >> nextFortune;
qDebug() << in;
}
{
switch (socketError) {
break;
qDebug() << "Host Not Found";
break;
qDebug() << "Connection Refused";
break;
default:
qDebug() << tcpSocket->errorString();
}
}
#include <QtNetwork>
#include "QuarqdClient.h"
QuarqdClient::QuarqdClient()
{
tcpSocket = new QTcpSocket(this);
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFortune()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(displayError(QAbstractSocket::SocketError)));
requestNewFortune();
//readFortune();
}
void QuarqdClient::requestNewFortune()
{
blockSize = 0;
tcpSocket->abort();
tcpSocket->connectToHost("192.168.1.2", 8168);
}
void QuarqdClient::readFortune()
{
qDebug() << "Reading!!";
QDataStream in(tcpSocket);
in.setVersion(QDataStream::Qt_4_0);
if (blockSize == 0) {
if (tcpSocket->bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
if (tcpSocket->bytesAvailable() < blockSize)
return;
QString nextFortune;
in >> nextFortune;
qDebug() << in;
}
void QuarqdClient::displayError(QAbstractSocket::SocketError socketError)
{
switch (socketError) {
case QAbstractSocket::RemoteHostClosedError:
break;
case QAbstractSocket::HostNotFoundError:
qDebug() << "Host Not Found";
break;
case QAbstractSocket::ConnectionRefusedError:
qDebug() << "Connection Refused";
break;
default:
qDebug() << tcpSocket->errorString();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks