I need to transfer an audio files byte by byte in socket and in receiver side I need to arrange it properly. For example, there is two audio files A and B, I have to read one byte from A and transfer, next I have to read first byte from B and transfer, then second byte from A and second byte from B like this the transfer has to be done till the EOF, in receiver side I have to organize properly received bytes for A and B.
The above one I tried in C++(Qt) in TCP sockets for one audio file.
QString path = "a4.wav";
QFile inputFile(path);
inputFile.open(QIODevice::ReadOnly);
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_4);
QByteArray q = inputFile.readAll();
block.append(q);
inputFile.close();
out.device()->seek(0);
qint32 x = 0;
unsigned int i = 0;
while (x < block.size()) {
qint32 y = socket->write(&block.data()[i],1); //Filling one byte in socket to write
x += y;
//qDebug() << y;
//qDebug() << x; // summary size you send, so you can check recieved and replied sizes
i++;
}
But here in above code I'm filling and writing one byte, but receiver side I'm getting bunch of bytes(for example receiving 14000bytes). It seems like the buffer in write socket fills maximum and then only transfer is happening. What I have to do, to write only one byte at a time?