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(showResult()),Qt::QueuedConnection);
connect(thread,SIGNAL(finished()),thread,SLOT(deletelater()),Qt::DirectConnection);
thread->start();
}
void timeserver:::incomingConnection(socketdescriptor,0);
{
TimeThread *thread = new TimeThread(socketDescriptor,0);
connect(thread,SIGNAL(finished()),dlg,SLOT(showResult()),Qt::QueuedConnection);
connect(thread,SIGNAL(finished()),thread,SLOT(deletelater()),Qt::DirectConnection);
thread->start();
}
To copy to clipboard, switch view to plain text mode
defination of class TimeThread
void TimeThread::run()
{
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";
}
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";
}
To copy to clipboard, switch view to plain text mode
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()));
connect(socket,SIGNAL(readyRead()),this,SLOT(read()));
To copy to clipboard, switch view to plain text mode
Bookmarks