[Qt-interest] Socket communication without threads
Bob Hood
bhood2 at comcast.net
Mon Mar 2 17:59:42 CET 2009
Predrag Manojlovic wrote:
> How can I write network server (multiple connections at same time, like
> chat server) without threads? That does not sounds possible.
It is. You just serialize the connections (store them into a processing
list as the connections come in), and process them at intervals,
checking to see if there's any incoming data, any data queued for them
from other connections, or if they have disconnected. This gives you a
serial server (as opposed to a concurrent server).
A concurrent server creates a thread to manage the connection, and then
data from/to the connection is routed back through the main thread,
which is responsible for making sure it gets posted to the correct
thread (or to all threads, in the case of a chat server). Communication
between the threads and the main server take place via a data queue that
is mutex protected.
--
Render me gone, |||
Bob ^(===)^
---------------------------------oOO--(_)--OOo---------------------------------
"If I owned Hell and Texas, I would rent out Texas and live in Hell."
- General Phil Sheridan
More information about the Qt-interest-old
mailing list