I get sine wave from server though TCP and plot it. Everything seems to be fine until I start sending something back at c>1000. After one byte sent, I still get data but the waveform of sine wave is changed. I'm sure that there are some missed data but I can't find bugs in my code. The transmission rate is about 1M bps.
The question is
When I write something to server, how it effects to socket?
Why the socket miss some data?
How can I fix it?
ssTcpClient::ssTcpClient(QObject *parent) : QObject(parent) { socket = new QTcpSocket(this); connect(socket, SIGNAL(connected()), this, SLOT(on_connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(on_disconnected())); } void ssTcpClient::on_connected() { qDebug() << "Client: Connection established."; connect(socket, SIGNAL(readyRead()), this, SLOT(on_readyRead())); in = new QDataStream(socket); } void ssTcpClient::on_readyRead(){ static quint32 c = 0; qDebug() << "c" << c++; QVector<quint8> data; quint8 buf; while(socket->bytesAvailable()>0){ //read data to buffer *in >> buf; data.append(buf); } //process data emit data_read(data); //if there are over 1000 data then send something back if(c>1000){ char msg[10]; msg[0] = 'c'; socket->write(msg,1); socket->flush(); } }