LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-31-2005, 06:55 AM   #1
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Tcp server for game


I'm currently creating an online poker game server and client for a university project and the server part and how it deals with connections is something I have been thrashing (bad joke) about with for a while.
The game is cross platform using:
for tcp: Berkeley sockets and winsock
for threads: pthreads and pthreads-win32

My first thoughts were that i could use a multi threaded server to deal with connections. ie the server opens a listening socket in a thread, listens for connections, accepts new connections and spawns a thread which deals with this connection. The problem with this design is its not scalable, ie 50 connections equals 50+ threads also theres alot of mutex's required for the queue's of messages which are very time consuming.

I am now thinking a poker table is contained within its own thread, yet each connection does not have its own thread. This cuts down on the number of threads required and therefore the amount of mutexs ( and condition mutex's) required. Instead the table thread uses the age old select() func to find the sockets where a message has come in or where a message may goto. This method also has its draw backs in that the select func has quite a bit of overhead ( fill the fd_sets check them and then deal with them ). Winsock has a maximum number of sockets which select can use, but a #define FD_SETSIZE ?? can override this; I can not find if bsd also has this restriction ( anybody know? ).

So I am thinking the second method here is much more scalable and the best of both worlds, anybody got any thoughts on this? If theres anymore info you think is needed before you can make a suggestion just ask, I didn't want to make this a massive post.

cheers.
<edit> I should add that I'm using c++ to code this and theses arn't the only designs I have come up with, but are the best of the bunch</edit>

Last edited by dmail; 12-31-2005 at 07:02 AM.
 
Old 12-31-2005, 08:59 PM   #2
Micah
Member
 
Registered: Apr 2002
Location: OK, USA
Distribution: Slackware64
Posts: 190

Rep: Reputation: 37
#define FD_SETSIZE -- BEFORE the other include (winsock[2].h for example - i think thats right)

I think BSD Sockets has the limitation as well but from what I have seen the limitation may not be a limitation (I've seen screenshots of 100+ connections and know the user did not touch fd_setsize...

SELECT seems to be the best way and the overhead I don't believe is that much... poll() (unix) or signals is another method but windows might have a limitation on like 64 events on a single thread (not verified by me)

using signals on Unix might be a good approach there - not sure on windows (it's basically an event)....

my 2 cents... take it for what its worth =)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I tell an NFS server to use TCP? BrianK Linux - Networking 7 12-03-2004 05:24 PM
Setting up a FTP server and Game server Spyiish Slackware 38 11-01-2004 05:32 AM
game not receving game list from master server Rnastyracer Linux - Games 2 04-02-2004 10:20 PM
TCP/IP server maxgor Programming 4 02-18-2003 02:37 PM
multiplayer tcp/ip game & loopback interface on RH 8 kkempter Linux - Networking 2 02-04-2003 12:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration