title: How does QTcpSocket write data to client?
body: <p>I wanna make a simple Qt app which can perform task like image below:  </p>
  
  <p><img src="https://i.stack.imgur.com/UYpdn.png" alt="enter image description here"></p>
  
  <p>I have learnt Fortune Server examples and actually I want this app is just like the combination of Fortune Server and Fortune Client.  </p>
  
  <p><strong>dialog.cpp</strong></p>
  
  <pre><code>void Dialog::on_btnListen_clicked(bool checked)
  {
      if(checked)
      {
          listener = new ServerSock(this);
          if(!listener-&gt;listen(QHostAddress::LocalHost,ui-&gt;boxPort-&gt;value()))
          {
              QMessageBox::critical(this,tr("Error"),tr("Cannot listen: %1").arg(listener-&gt;errorString()));
              ui-&gt;btnListen-&gt;setChecked(false);
              return;
          }
          else
          {
              qDebug() &lt;&lt; "Server is listening to port" &lt;&lt; listener-&gt;serverPort();
              ui-&gt;btnListen-&gt;setText(tr("Listening"));
              this-&gt;setWindowTitle(tr("Listening and Running"));
          }
      }
      else
      {
          listener-&gt;close();
          listener-&gt;deleteLater();
  
          ui-&gt;tmbListen-&gt;setText(tr("Listen again"));
          this-&gt;setWindowTitle(tr("Taking a rest"));
      }
  }
  </code></pre>
  
  <p><strong>serversock.cpp</strong>:</p>
  
  <pre><code>#include "serversock.h"
  
  ServerSock::ServerSock(QObject *parent) :
      QTcpServer(parent)
  {
  }
  
  void ServerSock::incomingConnection(int descriptor)
  {
      thread = new Threading(descriptor,this);
      connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater()));
      thread-&gt;start();
  }
  </code></pre>
  
  <p><strong>threading.cpp</strong>:</p>
  
  <pre><code>#include "threading.h"
  
  Threading::Threading(int descriptor, QObject *parent) :
      QThread(parent)
  {
      this-&gt;descriptorSocket = descriptor;
  }
  
  void Threading::run()
  {
      qDebug() &lt;&lt; "Thread is started...";
      socketThread = new QTcpSocket();
      if(!socketThread-&gt;setSocketDescriptor(this-&gt;descriptorSocket))
      {
          emit error(socketThread-&gt;error());
          return;
      }
  
      connect(socketThread,SIGNAL(readyRead()),this,SLOT(readyToRead()),Qt::DirectConnection);
      connect(socketThread,SIGNAL(disconnected()),this,SLOT(unconnected()),Qt::DirectConnection);
      qDebug() &lt;&lt; descriptorSocket &lt;&lt; "Connected";
      exec(); //loop
  }
  
  void Threading::readyToRead()
  {
      QByteArray data = socketThread-&gt;readAll();
  
      socketOut = new QTcpSocket();
      socketOut-&gt;connectToHost("192.168.0.1",8080);
      if(socketOut-&gt;waitForConnected(5000))
      {
  
          QByteArray query("GET http:// mysite. com/page HTTP/1.1\r\nHost: anothersite.com\r\r\r\n" + data); //example
          socketOut-&gt;write(query);
          socketOut-&gt;write("\r\r\r\n");
          socketOut-&gt;waitForBytesWritten(1000);
          socketOut-&gt;waitForReadyRead(3000);
  
          outPut = socketOut-&gt;readAll();
          if(socketOut-&gt;error() != socketOut-&gt;UnknownSocketError)
          {
              qDebug() &lt;&lt; socketOut-&gt;errorString();
              socketOut-&gt;disconnectFromHost();
  
              this-&gt;quit();
              socketThread-&gt;abort();
          }
          else
          {
          socketOut-&gt;close();
          }
      }
      else
      {
          qDebug() &lt;&lt; "Cannot connected";
      }
  
      if(!outPut.isNull())
          socketThread-&gt;write(outPut); 
  
      qDebug() &lt;&lt; descriptorSocket &lt;&lt; " Data in: " &lt;&lt; data;
  
  void Threading::unconnected()
  {
      qDebug() &lt;&lt; "Disconnected";
      socketThread-&gt;abort();
      exit(0);
      deleteLater();
  }
  </code></pre>
  
  <p>The problem is that I don't know how to return data from remote host to the local client, like the image below:</p>
  
  <p><img src="https://i.stack.imgur.com/5Aiqk.jpg" alt="enter image description here"></p>
  
  <p>it sends request, but there is no response. How to accomplish this?</p>