jknotzke
24th October 2009, 20:16
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()
{
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::Socket Error 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();
}
}
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()
{
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::Socket Error 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();
}
}