Server architecture advice needed :)

Moderator
Posts: 373
Joined: 2006.08
Post: #1
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 Smile
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Ever heard of select()?
Quote this message in a reply
Moderator
Posts: 373
Joined: 2006.08
Post: #3
that sounds.....vaguely familiar, but no, not really; I guess I'll look into it Smile
Thanks,
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  CrystalEngine server solution for any game project Aldex 0 3,424 Sep 1, 2011 01:45 AM
Last Post: Aldex
  P2P or Client/Server? TokyoDan 2 4,649 Aug 3, 2009 06:15 AM
Last Post: georgiph
  Connect to Server from Iphone BugSniper 6 9,411 Jul 15, 2009 04:57 PM
Last Post: BugSniper
  Server/database interaction in C++ using sockets wyrmmage 2 5,225 Jan 20, 2007 02:17 PM
Last Post: wyrmmage
  Writing a Server unknown 9 5,356 Jun 2, 2006 09:46 PM
Last Post: ravuya