title: Qt Server Client Code
body: <p>I am a new to the QT programming. my server/client codes are quite simple but they are not working.......</p>
  
  <p>pls have a look to find problems in my codes, thanks.</p>
  
  <p>SERVER:</p>
  
  <pre><code>int main(int argc, char** argv)
  {
  //  QApplication app(argc, argv);
  //      Server server;
          QTcpSocket *client_sock =  NULL;
          QTcpServer server;
          server.listen(QHostAddress::Any,8888);
          char buff[100];
  
      while(1)
      {
              if(server.hasPendingConnections())
              {
                      client_sock = server.nextPendingConnection();
              }
              if(client_sock)
              {
                      qint64 n_rtn;
                      n_rtn = client_sock-&gt;bytesAvailable();
                      client_sock-&gt;readLine(buff,n_rtn);
                      std::cout&lt;&lt;buff;
              }
      }
  //  return app.exec();
  }
  </code></pre>
  
  <p>CLIENT:</p>
  
  <pre><code>int main(int argc, char** argv)
  {
  //  QApplication app(argc, argv);
    QTcpSocket client;
    QHostAddress addr("127.0.0.1");
    client.connectToHost(addr,8888);
  
    if(client.isWritable())
    {
          client.write("Hello World!\n");
    }
  
    client.close();
  
  //  return app.exec();
  }
  </code></pre>
  
  <p>Thanks</p>