Hello, I am designing and making a server that should be able to handle about 100+ hits per second. The information I am getting from the server is just the HTTP header. Based on the information from the header, it will query a database(different thread) for some information and send the final information back to the QTcpServer which create an output string, and send back a HTTP Response. I am having a big problem with this that I cannot debug. My code look similar to this:

Qt Code:
  1. TCPInterface::TCPInterface(QObject *parent): QTcpServer(parent)
  2. {
  3. //start listening for tcp traffic on port 80
  4. listen(QHostAddress::Any, 80);
  5.  
  6. connect(this,SIGNAL(sendInfo(QTcpSocket*, QString *)), databaseThread, SLOT(recieveInfo(QTcpSocket*, QString*)));
  7. connect(databaseThread, SIGNAL(sendToTCPSend(QTcpSocket *, QString *)), this, SLOT(TCPSend(QTcpSocket*, QString*)));
  8.  
  9. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void TCPInterface::incomingConnection(int socket)
  2. {
  3. QTcpSocket *s = new QTcpSocket(this);
  4.  
  5. connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
  6. // connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
  7.  
  8. s->setSocketDescriptor(socket);
  9. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //void TCPInterface::discardClient()
  2. //{
  3. // QTcpSocket* socket = (QTcpSocket*)sender();
  4. // socket->deleteLater();
  5. //}
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void TCPInterface::readClient()
  2. {
  3. QTcpSocket* socket = (QTcpSocket*)sender();
  4.  
  5. QString header;
  6. while(socket->canReadLine())
  7. {
  8. header += socket->readLine();
  9. }
  10.  
  11. emit sendInfo(socket, headerInfo);
  12. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void databaseThread::recieveInfo(QTcpSocket* socket, QString* headerInfo)
  2. {
  3. QString*outputInfo = getDatabaseInfo(headerInfo);
  4. emit sendToTCPSend(socket, outputInfo);
  5. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void TCPInterface::TCPSend(QTcpSocket* socket, QString* outputInfo);
  2. {
  3. QString response = "HTTP/1.0 200 Ok\r\n";
  4. response += "Content-Type: text/html; charset=\"utf-8\"\r\n";
  5. response += "\r\n" + *outputInfo + "\n";
  6.  
  7. if(socket->isWritable() && socket->isOpen())
  8. {
  9. socket->write(response.toAscii());
  10. }
  11. //socket->disconnectFromHost();
  12. socket->close();
  13. delete headerInfo;
  14. }
To copy to clipboard, switch view to plain text mode 

I having one main problem which I have an idea what it is, but cannot find a solution to fix it.

My problem is my memory is constantly increasing as I get more hits. I am sure the cause of this is my QTcpSockets are never being deleted, since I am just closing them. However when I don't use close, and use disconnectFromHost and disconnected/discardClient slot/signal my server will crash with heavy traffic(no message or anything so I am not sure of the exact reason of the crash). Has anyone run into this problem before? Any ideas at all.