How can i get reading the message from client,Sorry My English
I was using this example http://wiki.qtcentre.org/index.php?title=Simple_Chat

Server.cpp
Qt Code:
  1. connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
  2. connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));
  3.  
  4. QHBoxLayout *buttonLayout = new QHBoxLayout;
  5. buttonLayout->addStretch(1);
  6. buttonLayout->addWidget(quitButton);
  7. buttonLayout->addStretch(1);
  8.  
  9.  
  10. QVBoxLayout *mainLayout = new QVBoxLayout;
  11. mainLayout->addWidget(statusLabel);
  12. mainLayout->addLayout(buttonLayout);
  13. setLayout(mainLayout);
  14.  
  15. setWindowTitle(tr("Fortune Server"));
  16. }
  17.  
  18. void Server::sendFortune()
  19. {
  20. QTcpSocket *tcpSocket = tcpServer->nextPendingConnection();
  21.  
  22. connections.append(tcpSocket);
  23. QBuffer* buffer = new QBuffer(this);
  24. buffer->open(QIODevice::ReadWrite);
  25. buffers.insert(tcpSocket, buffer);
  26.  
  27. out.setDevice(tcpSocket);
  28. QString tiedosto=haeTiedosto(kuvaIndex);
  29. QFile file(tiedosto);
  30. file.open(QIODevice::ReadOnly);
  31. fstr.setDevice(&file);
  32.  
  33.  
  34. file.seek(0);
  35. char* data = new char[65536];
  36. while(!file.atEnd())
  37. {
  38. int read = fstr.readRawData(data, 65536);
  39. int sent = out.writeRawData(data, read);
  40. }
  41.  
  42. delete[] data;
  43.  
  44. tcpSocket->waitForBytesWritten();
  45.  
  46.  
  47.  
  48. connect(tcpSocket, SIGNAL(readyRead()), SLOT(receiveMessage()));
  49. connect(tcpSocket, SIGNAL(disconnected()), SLOT(removeConnection()));
  50.  
  51.  
  52. }
  53. void Server::removeConnection()
  54. {
  55.  
  56. QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
  57. QBuffer* buffer = buffers.take(socket);
  58. buffer->close();
  59. buffer->deleteLater();
  60. connections.removeAll(socket);
  61. socket->deleteLater();
  62.  
  63.  
  64.  
  65.  
  66. }
  67.  
  68. void Server::receiveMessage()
  69. {
  70.  
  71. QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
  72. QBuffer* buffer = buffers.value(socket);
  73.  
  74. // missing some checks for returns values for the sake of simplicity
  75. qint64 bytes = buffer->write(socket->readAll());
  76. // go back as many bytes as we just wrote so that it can be read
  77. buffer->seek(buffer->pos() - bytes);
  78. // read only full lines, line by line
  79. while (buffer->canReadLine())
  80. {
  81. QByteArray line = buffer->readLine();
  82. foreach (QTcpSocket* tcpSocket, connections)
  83. {
  84. int d=line.toInt();
  85. QString data=data.setNum(d);
  86. statusLabel->setText(data);
  87. }
  88.  
  89. }
To copy to clipboard, switch view to plain text mode