PDA

View Full Version : Multiple QTcpServer instances and message queue



sandor
22nd May 2012, 11:24
Some might have an idea what to do...

There are 3 QTcpServers listening or 3 different ports. I override incomingConnection or connect signal newConnection; those produce the same behavior. The problem is that the 3 servers must do a fair bit of work before sending a response and while one server processes the incoming connection, another thread cannot receive a connection since the main application message queue is blocked (I can create QThreads to process later but that still costs some speed).

So, how can I ensure that the 3 QTcpServer instances own their own message queue and work really independently and receive messages really independently too? I tried to make classes extending QThread, also tried moveToThread but I am getting the "QObject: Cannot create children for a parent that is in a different thread." error message when trying to do that (surprisingly setMaxPendingConnections works, no complaints from Qt, but when it comes to listen... then it does not work).

Any idea?

^NyAw^
22nd May 2012, 16:18
Hi,

First, create a QThread derived class "myThreadClass"
When a new incoming connection comes, you can create a "myThreadClass" object and pass the socketDescriptor to it. Finally call "myThreadClass->start()".
There you can create a QTcpSocket with the socketDescriptor and finally call "exec()" to enter into the eventLoop. In "myThreadClass" you will have to do the "work".

Hope it helps,