PDA

View Full Version : Threaded server.



nithinin2001
13th November 2007, 15:21
Hi,
I was trying to create a threaded tcp server which will create a new thread for each and every clients. so i passed the tcp socket descriptor to the corresponding thread. i have mapped the signal ready read in the same run function to the slot of an object created in the same thread's run. but i am getting an error. not actually an error but some run time problem. but on run time the clients are getting connected but, the ready read is not invoked even if data is sent. an exception is thrown by qt notifier.
please help me out to solve the problem
Nithin

wysota
13th November 2007, 16:09
The problem is probably that you didn't run an event loop for each of the threads and maybe also created the sockets in the main thread context and you don't get notified of incoming socket events because they are not handled by the proper thread. Make sure you call QThread::exec() from each of the threads if you want to use signal-slot connections.

anoop
15th November 2007, 17:37
well i dont know if this helps but i had the same problem , even after calling the exec

in the run method, the problem was i used the built in QTcpServer socket , hooked a slot at

connected signal, called the pendingConnection function , took socketdescriptor of the

QTcpSocket returned by the function created my QThread class instance passing the

socketdesicritor. The point to remeber is even if you created a TcpSocket and set the

scoket descriptor in the run method , it wont work. so inherit from QTcpServer class and

override the incoming connection function take the socketdescriptor passed in start your custom thead here passing the descriptor, and create the QTcpSocket class instance
from run function and set the passed descriptor.