Sure. Mt requirement here is to simulate an environment where 'n' end systems are simultaneuosly posting x requests each, to a server.
I have a class, Http, which implements sending x requests to the server as follows using the QHttp n QHttpRequestHeader.
The constructor of this class has
op->setHost(192.168.0.89);
QHttp op=new QHttp();
op->setHost(192.168.0.89);
To copy to clipboard, switch view to plain text mode
while a function info() of the same class, implements
header.setValue( "Host", "192.168.0.89" ) ;
header.setContentType( "application/x-www-form-urlencoded" ) ;
op->request(header,logData);
QHttpRequestHeader header( "POST", "server.php" ) ;
header.setValue( "Host", "192.168.0.89" ) ;
header.setContentType( "application/x-www-form-urlencoded" ) ;
op->request(header,logData);
To copy to clipboard, switch view to plain text mode
I tested this and it is working perfectly.Now in order to get n systems doing this simultaneously, I am using a class inherited from QThread. I have reimplemented run() to create a Http object and call info().
In the main(), i have
for(int i=0;i<noOfThreads;i++)
{
MyThread *t = new MyThread(noOfLogs);
list.append(t);
QObject::connect(t,
SIGNAL(finished
()),t,
SLOT(deleteLater
()));
t->start();
}
QList <MyThread *> list;
for(int i=0;i<noOfThreads;i++)
{
MyThread *t = new MyThread(noOfLogs);
list.append(t);
QObject::connect(t, SIGNAL(finished()),t, SLOT(deleteLater()));
t->start();
}
To copy to clipboard, switch view to plain text mode
This does not work, not a single request is sent. However if i call run() instead of start(), it works. But i guess, i should not be calling run() as then each thread will be created one after the other i the loop, which beats simultaneous requirement.
I however tried
QObject::connect(t,
SIGNAL(finished
()),t,
SLOT(CallRun
()));
QObject::connect(t, SIGNAL(finished()),t, SLOT(CallRun()));
To copy to clipboard, switch view to plain text mode
Then the exe, works with a call to start().
Can you point where i am probably going wrong?
Thanks a lot in advance.
Bookmarks