Hi all,
I have a trouble with QTcpSocket readyRead() signal.
My Qt application act as client and the server send messages in an asyncronous way.
The problem is that I notice that sometimes a message isn't signaled by the readyRead().
The message is always the same message in the sequence, but the problem don't always occours.
I'm sure that message comes because I see the network traffic with wireshark.

Here is my client code:
Qt Code:
  1. {
  2. // in class ctor...
  3. m_socket = new QTcpSocket(this);
  4. connect(m_socket, SIGNAL(connected()), this,SLOT(connected()));
  5. connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this,SLOT(error(QAbstractSocket::SocketError)));
  6. connect(m_socket, SIGNAL(disconnected()), this,SLOT(disconnected()));
  7. connect(m_socket, SIGNAL(readyRead()), this,SLOT(receiveMessage()));
  8. }
  9.  
  10. void XmlSocket::receiveMessage()
  11. {
  12. int bytesRead;
  13. // READ_BUF_SIZE is defined as 512 and the message I receive are 100 chars...
  14. char buf[READ_BUF_SIZE];
  15.  
  16. // read data from socket
  17. // NB: loop only if we read more than 512 bytes...
  18. QString msgString;
  19. do {
  20. bzero(buf,READ_BUF_SIZE);
  21.  
  22. bytesRead = m_socket->read(buf, READ_BUF_SIZE);
  23. if(bytesRead < 0)
  24. qCritical("Error reading data from socket %d",bytesRead);
  25. else if(bytesRead == 0)
  26. qWarning("No more data on socket...");
  27.  
  28. msgString += QString(buf);
  29. qDebug("++ %s", qPrintable(msgString));
  30. } while(bytesRead == READ_BUF_SIZE);
  31.  
  32. // emit signal with available data
  33. if(!msg.setContent(msgString))
  34. qWarning("Error setting content for string %s", qPrintable(msgString));
  35.  
  36. emit messageReceived(msg);
  37. }
To copy to clipboard, switch view to plain text mode 

I have see that the message that I don't receive is sent just 3 ms after the previous one...
Send time
[28/04 16:33:30:423] message 1, received
[28/04 16:33:30:525] message 2, received
[28/04 16:33:30:528] message 3, NOT RECEIVED
[28/04 16:33:31:290] message 4, received

This could be a performance issue???

Now I try to solve using standard socket, but I wish to use QTcpSocket because they offer a simple API and for portability reason.

I am using Qt 4.7.1 on linux platform.