Results 1 to 8 of 8

Thread: Server with multiple clients without threads

  1. #1
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows
    Wiki edits
    1

    Default Server with multiple clients without threads

    Hi all,

    I am very new in Qt. i am trying to implement the following link:
    http://www.qtcentre.org/wiki/index.p...ithout_threads

    But their is no code ....
    Can anyone help me for the example....

  2. #2
    Join Date
    May 2010
    Location
    slovakia
    Posts
    47
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: Server with multiple clients without threads

    why not use threading? every modern computer support threading and got more than one CPU core.... and PC's of tommorrow gonna have even more cores..

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Server with multiple clients without threads

    Using threads when no threads are needed is a sign of very poor design.

    The basic idea is this:
    In your server implementation:
    * Create a list that keeps track of client sockets
    * For each new connection, add the socket to the list
    * Connect the useful signals of the socket to a slot in your server implementation
    * Signals like readyRead() and disconnected()
    * Do not use the waitFor... functions

  4. #4
    Join Date
    May 2010
    Location
    slovakia
    Posts
    47
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: Server with multiple clients without threads

    what is poor about using multithreading on multi-core processors??? i guess it's more fear of threading...

    Using threads when no threads are needed


    if you program real server app, which will run on 8-24 thread CPU (i7, new AMD), NOT using threading is poor decision... simply coz you dont take advantage of HW.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Server with multiple clients without threads

    Quote Originally Posted by daemonna View Post
    what is poor about using multithreading on multi-core processors???
    Nothing if you have more cores in your machine than processes in your systems + maximum number of clients you handle concurrently. And if you really like synchronizing threads But in a general case there is no point in using threading simply because you can.

    if you program real server app, which will run on 8-24 thread CPU (i7, new AMD), NOT using threading is poor decision... simply coz you dont take advantage of HW.
    Bearing the fact that most of the time all your threads will be doing nothing waiting for network to deliver data to them, you won't be really "taking advantage of HW" - your computer will just spend most of its time context switching between threads and doing bookkeeping. There is simply no advantage in doing networking by itself as multithreaded if you can do it another way. I don't say threads shouldn't be used to do the actual work on behalf of networking clients but not to do networking itself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Server with multiple clients without threads

    I suggest to read this great article "The C10K problem", strategies to handle a lot of traffic. It's what your server will do and how much traffic will have that will determine threading or not.
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  7. #7
    Join Date
    May 2010
    Location
    slovakia
    Posts
    47
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: Server with multiple clients without threads

    Quote Originally Posted by Archimedes View Post
    I suggest to read this great article "The C10K problem", strategies to handle a lot of traffic. It's what your server will do and how much traffic will have that will determine threading or not.
    that's it... if you just wanna play, or wanna make server for few users, than dont bother with threads, coz

    Quote Originally Posted by quote
    Bearing the fact that most of the time all your threads will be doing nothing waiting for network to deliver data to them, you won't be really "taking advantage of HW"
    is actually right.

    But if you wanna do (or you're planning to do) serious work for some enterprise (document server, some new form of corporate chat, game server a la "eve-online", than threads are 'MUST HAVE' and you should learn it....

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Server with multiple clients without threads

    Quote Originally Posted by daemonna View Post
    But if you wanna do (or you're planning to do) serious work for some enterprise (document server, some new form of corporate chat, game server a la "eve-online", than threads are 'MUST HAVE' and you should learn it....
    Read my response again And trust me, I know how (and most of all when) to use threads.

    By the way, I don't think a "chat server" needs to be multithreaded. As for game servers and games themselves, most of them are unfortunately singlethreaded in nature - the networking is done multithreaded but the core is singlethreaded because of synchronization issues. And most of the time network bandwidth is the bottleneck and not the processing power which places multithreaded networking in a dubious position.

    And most people do networking in multiple threads simply because they don't have skills, knowledge or tools to do it in a single thread.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 23
    Last Post: 17th April 2013, 09:52
  2. Server with multiple clients without threads
    By kernel.roy in forum Newbie
    Replies: 2
    Last Post: 9th September 2010, 04:53
  3. QLocalServer with multiple clients — proper handling
    By indiocolifa in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2010, 00:01
  4. Replies: 7
    Last Post: 10th May 2010, 11:26
  5. Extend QTcpServer to handle multiple clients
    By DiamonDogX in forum Qt Programming
    Replies: 5
    Last Post: 24th February 2010, 19:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.