Hello friends i am working on a software where i need to transfer data from one system to another using TCP/IP . I used the fortune client and fortune server example code as base and made this program but i am having problem in in receiving after the first transfer there is some problem not able to receive the data properly.

Data Sending Side
Qt Code:
  1. tcpSocket = new QTcpSocket(this);
  2. connect(tcpSocket, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));
  3. rowcnt=1;
  4. tcpServer = new QTcpServer(this);
  5. if (!tcpServer->listen()) {
  6. QMessageBox::critical(this, tr("Data Server"),
  7. tr("Unable to start the server: %1.")
  8. .arg(tcpServer->errorString()));
  9. close();
  10. return;
  11. }
  12.  
  13. statusLabel->setText(tr("The server is running on port %1.\n"
  14. "Run the Fortune Client example now.")
  15. .arg(tcpServer->serverPort()));
  16.  
  17. }
  18.  
  19. ControlPanel::~ControlPanel()
  20. {
  21.  
  22. }
  23. void ControlPanel::sendFortune()
  24. {
  25. QByteArray block;
  26. QDataStream out(&block, QIODevice::WriteOnly);
  27. out.setVersion(QDataStream::Qt_4_0);
  28. out << (quint16)0;
  29. out << tempdata;
  30. out.device()->seek(0);
  31. out << (quint16)(block.size() - sizeof(quint16));
  32.  
  33. QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
  34. connect(clientConnection, SIGNAL(disconnected()),
  35. clientConnection, SLOT(deleteLater()));
  36.  
  37. clientConnection->write(block);
  38. //clientConnection->disconnectFromHost();
  39. qDebug()<<tempdata;
  40. tempdata.clear();
  41. }
  42.  
  43. void ControlPanel::extract()
  44. {
  45. // Retrieving data from db and appending it to tempdata and then calling the function sendFortune()
  46.  
  47. sendFortune();
  48. }
  49. void ControlPanel::on_pushButton_clicked()
  50. {
  51. // I wanted to send data every Second so i am calling extract() every second.
  52. connect(timerdraw, SIGNAL(timeout()), this, SLOT(extract()));
  53. timerdraw->start(1000);
  54. }
To copy to clipboard, switch view to plain text mode 
This is the receiver side of the program.
Qt Code:
  1. setupUi(this);
  2. portLineEdit->setValidator(new QIntValidator(1, 65535, this));
  3. tcpSocket = new QTcpSocket(this);
  4. timerdraw = new QTimer(this);
  5. timerreq = new QTimer(this);
  6.  
  7. connect(hostLineEdit, SIGNAL(textChanged(const QString &)),
  8. this, SLOT(enablepushButton()));
  9. connect(portLineEdit, SIGNAL(textChanged(const QString &)),
  10. this, SLOT(enablepushButton()));
  11. //connect(pushButton, SIGNAL(clicked()),
  12. // this, SLOT(requestNewFortune()));
  13. connect(pushButton_2, SIGNAL(clicked()), this, SLOT(close()));
  14. connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFortune()));
  15. connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
  16. this, SLOT(displayError(QAbstractSocket::SocketError)));
  17.  
  18.  
  19. }
  20. void TCP_DataReceiver::requestNewFortune()
  21. {
  22. pushButton->setEnabled(false);
  23. blockSize = 0;
  24. tcpSocket->abort();
  25. tcpSocket->connectToHost(hostLineEdit->text(),
  26. portLineEdit->text().toInt());
  27. }
  28. void TCP_DataReceiver::readFortune()
  29. {
  30. QDataStream in(tcpSocket);
  31. in.setVersion(QDataStream::Qt_4_0);
  32.  
  33. if (blockSize == 0)
  34. {
  35. if (tcpSocket->bytesAvailable() < (int)sizeof(quint16))
  36. return;
  37.  
  38. in >> blockSize;
  39. }
  40.  
  41. if (tcpSocket->bytesAvailable() < blockSize)
  42. return;
  43.  
  44. QString nextFortune;
  45. in >> nextFortune;
  46.  
  47. // if (nextFortune == currentFortune)
  48. // {
  49. // QTimer::singleShot(0, this, SLOT(requestNewFortune()));
  50. // return;
  51. // }
  52.  
  53. currentFortune = nextFortune;
  54.  
  55. statusLabel->setText(currentFortune);
  56. textBrowser->append(currentFortune);
  57. currentFortune.clear();
  58. pushButton->setEnabled(true);
  59. }
To copy to clipboard, switch view to plain text mode 

I am not able to figure out if my problem is on the Data receiving side or the sending side. I have connected two windows systems with a cross cable RJ45 connector. I wanted to send data every second to the other system where i run the receiving side of the program.. The connection breaks after some data is transferred to other system.. Pls tell me if i am going wrong some where. ?

Thank You