title: How to read complete data using QTcpSocket (Qt4.7)
body: <p>I created a TcpServer in order to receive data from a client. The client sends a lot of messages and I would like to read them. So far my TcpServer.cpp looks like this : </p>
  
  <pre><code>
  
  void TcpServer::serverStart()
  {
      server = new QTcpServer(this);
      if (!server-&gt;listen(QHostAddress("192.168.x.x"), 48583))
      {
          qDebug() &lt;&lt; "Not listening";
          server-&gt;close();
          delete server;
          return;
      }
      else {
          qDebug() &lt;&lt; "Listening";
      }
  
  connect(server, SIGNAL(newConnection()), this, SLOT(newConnection()));
  
  
  }
  
  
  
  void TcpServer::newConnection()
  {
  
      socket = server-&gt;nextPendingConnection();
      qDebug() &lt;&lt; "Client connected";
  
      connect(socket, SIGNAL(readyRead()), this, SLOT(getData()));
      connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
  }
  
  
  void TcpServer::getData()
  {
  
  QByteArray buffer;
  
  while (socket-&gt;bytesAvailable())
      {
          buffer.append(socket-&gt;readAll());
         }
  qDebug() &lt;&lt; buffer;
      }
  
  
  
  
  void TcpServer::serverStop()
  {
      server-&gt;close();
      delete server;
  }
  
  </code></pre>
  
  <p>I know my getData function needs a lot more in order to receive everything but I don't understand the steps needed to do that.If someone could give me some pointers I would be grateful !  </p>