Server architecture advice needed :)
So, I'm building a server that accepts Windows and (hopefully soon) Mac connections; although I'm programming the server in WinSock, I believe that the design would be pretty much the same on all platforms. I asked a friends who has more experience in this field than I do, and he said that a good way to design my server would be to either:
First Design:
Have a thread that was entirely in a while(1==1) loop, that listen()'ed for incoming requests, and then put them on the stack, and then a seperate thread that accept()'ed any pending connections and then went through all of the connections that had already been accepted and did any appropriate actions (like recv(), send(), updating the database, etc.).
Second design:
Have a thread that was in a while(1==1) loop that listen()'ed for incoming requests, then immediately acccept()'ed them and spawned a new thread for each connection. Each connection thread would then be in a loop until the client disconnected from the server, then the thread would be destroyed; inside each connection thread, send(), recv(), and so forth actions would be performed.
So, which of these is better? Are there any huge flaws that I am missing, or are these designs both completely off the track? I did skim the articles in the Sticky at the top of the board, although I could re-read them in detail if necessary.
Thanks
-wyrmmage
First Design:
Have a thread that was entirely in a while(1==1) loop, that listen()'ed for incoming requests, and then put them on the stack, and then a seperate thread that accept()'ed any pending connections and then went through all of the connections that had already been accepted and did any appropriate actions (like recv(), send(), updating the database, etc.).
Second design:
Have a thread that was in a while(1==1) loop that listen()'ed for incoming requests, then immediately acccept()'ed them and spawned a new thread for each connection. Each connection thread would then be in a loop until the client disconnected from the server, then the thread would be destroyed; inside each connection thread, send(), recv(), and so forth actions would be performed.
So, which of these is better? Are there any huge flaws that I am missing, or are these designs both completely off the track? I did skim the articles in the Sticky at the top of the board, although I could re-read them in detail if necessary.
Thanks

-wyrmmage
Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Ever heard of select()?
that sounds.....vaguely familiar, but no, not really; I guess I'll look into it 
Thanks,
-wyrmmage

Thanks,
-wyrmmage
Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| CrystalEngine server solution for any game project | Aldex | 0 | 2,952 |
Sep 1, 2011 01:45 AM Last Post: Aldex |
|
| P2P or Client/Server? | TokyoDan | 2 | 4,240 |
Aug 3, 2009 06:15 AM Last Post: georgiph |
|
| Connect to Server from Iphone | BugSniper | 6 | 8,172 |
Jul 15, 2009 04:57 PM Last Post: BugSniper |
|
| Server/database interaction in C++ using sockets | wyrmmage | 2 | 4,753 |
Jan 20, 2007 02:17 PM Last Post: wyrmmage |
|
| Writing a Server | unknown | 9 | 5,070 |
Jun 2, 2006 09:46 PM Last Post: ravuya |
|

