PDA

View Full Version : question about socket and threads?



oob2
26th February 2007, 19:49
Hi,

My program was using QT3's QSocketDevice. There are 3 threads in my program.
The main thread first create the QSocketDevice, and connect to the host. Once connected, the main thread will not access to this QSocketDevice anymore. Then, I created one sending thread, and one receiving thread. Both sending thread and receiving thread access to the same QSocketDevice which was created by main thread.

But, now, I tried to switch to QT4's QAbstractSocket or QTckSocket. How can I do that?

Thread A: create socket sd and connect it to the host.
Thread B: taking care of sending data to the host using socket sd.
Thread C: taking care of receiving data from the host using socket sd.

Thanks.

wysota
26th February 2007, 21:11
You can't do it this way. The socket has to be handled by the same thread (or to be more precise, by one thread at once).

fullmetalcoder
27th February 2007, 11:42
however as a thread has it's own event loop you don't need to split various socket management tasks in several threads... just connect proper slots and everything will be fine :)