The problem is that my run function is returning only the first few characters (up until the first whitespace actually) of the data that has arrived on the socket. So it returns
200
200
To copy to clipboard, switch view to plain text mode
instead of
200 newsreader2.eweka.nl NNRP Service Ready - news.eweka.nl (posting ok)
200 newsreader2.eweka.nl NNRP Service Ready - news.eweka.nl (posting ok)
To copy to clipboard, switch view to plain text mode
Anyone know why? It works fine if I uncomment the readLine() function, but I'm trying to get it to work using a datastream.
void Connection::run()
{
const int Timeout = timeout * 1000;
emit emitData( "run() commencing" );
quit = false;
socket.connectToHost( hostName, port );
if( !socket.waitForConnected( Timeout ) ){
emit emitData( "returning ( socket.waitForConnected )" );
return;
}
while(!quit){
emit emitData( "entering loop" );
if( !socket.waitForReadyRead( Timeout ) ){
emit emitData( "returning ( socket.waitForReadyRead )" );
return;
}
// while( socket.canReadLine() ){
// emit emitData( socket.readLine() );
// emit emitData( QString::number( socket.bytesAvailable() ) );
// if( socket.waitForReadyRead( Timeout ) ){
// emit emitData( "returning ( socket.bytesAvailable )" );
// return;
// }
// }
dataStream >> data;
emit emitData( data );
}
}
void Connection::run()
{
QTcpSocket socket;
const int Timeout = timeout * 1000;
emit emitData( "run() commencing" );
quit = false;
socket.connectToHost( hostName, port );
if( !socket.waitForConnected( Timeout ) ){
emit emitData( "returning ( socket.waitForConnected )" );
return;
}
while(!quit){
emit emitData( "entering loop" );
if( !socket.waitForReadyRead( Timeout ) ){
emit emitData( "returning ( socket.waitForReadyRead )" );
return;
}
QString data;
QTextStream dataStream( &socket );
// while( socket.canReadLine() ){
// emit emitData( socket.readLine() );
// emit emitData( QString::number( socket.bytesAvailable() ) );
// if( socket.waitForReadyRead( Timeout ) ){
// emit emitData( "returning ( socket.bytesAvailable )" );
// return;
// }
// }
dataStream >> data;
emit emitData( data );
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks