I am still very new to C++/Qt programming. I was hoping that someone could shed some light on something for me:
Code:
void Thread::run() { //initalize socket, start connection and detect data available if (socket->setSocketDescriptor(sock)) { QByteArray block; out << (quint16)0; out << welcomeMsg; out.device()->seek(0); out << (quint16)(block.size() - sizeof(quint16)); socket->write(block); } { if (socket->bytesAvailable() < 1) { qDebug("Waiting for data..."); if (!socket->waitForReadyRead()) break; } // while (socket->bytesAvailable() > 0) // { if (socket->bytesAvailable() > 0) { qDebug("Data available"); if (incomingBlock.contains("xml") && !incomingBlock.isEmpty()) { dataHandler = new xmlDataHandler; dataHandler->doParse( &incomingBlock ); } /* char c; socket->getChar(&c); printf("%c", c); */ } // } } qDebug("Connection closed"); }
To explain a little bit. This is the run code for a thread that is created and started each time a new connection is requested. I am trying to stream short bits of dynamically created xml like data to the server from a client. I basically want to know when the end of a stream has been reached. How do you figure out the data that is coming across the socket. I assume the beginning of the stream is the header information. Then the data is passed. How do I separate those and only save the data and close the connection after the data is finished streaming? Thanks in advance. Even pointing to a good sockets tutorial would suffice.
