Hello, I'm trying to connect a very basic twisted "hello world" server with a basic Qt tcp client.
The client uses these Signals:
connect(&socket, SIGNAL(connected()), this, SLOT(startTransfer()));
connect(&socket, SIGNAL(readyRead()), this, SLOT(readServer()));
and then readServer() looks like this:
ui->resultLabel->setText("Reading..");
QDataStream in(&socket);
//in.setVersion(QT_4_0);
if (blockSize == 0) {
if (socket.bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
if (socket.bytesAvailable() < blockSize)
return;
QString theResult;
in >> theResult;
qDebug() << in;
qDebug() << theResult;
ui->resultLabel->setText(theResult);
The server I'm using for testing purposes is simply an example grabbed off of twisted's docs
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
### Protocol Implementation
# This is just about the simplest possible protocol
class Echo(Protocol):
def dataReceived(self, data):
"""
As soon as any data is received, write it back.
"""
self.transport.write(data)
def main():
f = Factory()
f.protocol = Echo
reactor.listenTCP(8000, f)
reactor.run()
if __name__ == '__main__':
main()
readServer() is being called just fine, but it never seems to collect any of the data. I've read somewhere that this might have to do with QDataStream's << operator because python isn't exactly sending it in pieces like Qt expects.
I admit I'm not very savvy with C++ or Qt, but the idea of the project is to write a client to work with an existing twisted server, so while the client can be changed I'm left with no choice but to make it work with this server.
Thanks in advance for any help.