PDA

View Full Version : mutithread in http-server



chuengchuenghq
6th June 2008, 03:29
I wanna develop a http server using muti-thread,during the communication connections,which some must keep-alive.
how the plan it.
or someone give me the source code with explainatons..

in addition,
see the defination if class timeserver

void timeserver:::incomingConnection(socketdescriptor,0 );
{

TimeThread *thread = new TimeThread(socketDescriptor,0);
connect(thread,SIGNAL(finished()),dlg,SLOT(showRes ult()),Qt::QueuedConnection);
connect(thread,SIGNAL(finished()),thread,SLOT(dele telater()),Qt::DirectConnection);

thread->start();

}


defination of class TimeThread
void TimeThread::run()
{
QTcpSocket socket = new QTcpSocket;
if(!socket->setSocketDescriptor(socketDescriptor))
{
return;


}

socket->write("aaa");
connect(socket,SIGNAL(readyRead()),this,SLOT(read( )));// never exec the read() function when the client has sent the data, why?





}

void TimeThread::read()
{
qDebug() << "reading data";

}

as u see,I can only send data to client, how can i receive data from client,where should the slot function set?//
connect(socket,SIGNAL(readyRead()),this,SLOT(read( )));

jacek
8th June 2008, 00:24
You have to start the event loop in the thread to make QTcpSocket work. See QThread::exec().