Advertisement

Writing a poker server, how? (concept, threads, winsock)

Started by April 10, 2003 08:02 AM
-1 comments, last by xlazyx 21 years, 10 months ago
Hey! I''m trying to write a poker server, but I''m kindof stuck. Here''s what I have planned for now: I''ll run one main thread which accepts incoming connections (poker clients) and then creates a new socket for each player. There will also be one thread for each poker table going on, i.e. [Table1] has one thread where a game of Draw poker is played and [Player3] and [Player7] are active. [Table2] has one thread where a game of Hold''Em is played, and [Player4] and [Player7] is playing, [Player3] is watching. A poker round has many stages, including sending out the same info to all players (including the ones only watching), for example the info "player x folded". All players need to know this. There will also be situastions where only one player gets a message, for example "how much do you bet?". A player can play/watch serveral tables at once, and there is also a lobby thread that keeps track of which games are going on, the average pots and so on. NOW! The problem is: How will I send out all this info to the clients? Ok, I''m using winsock, so my idea is that each player object has a handle to the soket that player is connected to. What im not sure of, should i use one thread for each player? Or a thread with a list of each player, and that thread goes trough the list in a loop, sending all qued up messages for each player object? The problem with the first idea is that there will be lots of thread, mutexes and all that stuff. The problem with the last is that if one client is lagged it will affect all players, even those playing at different tables, because all players are in the same list. I guess this could be solved using non blocking sockets, but i read in a guide here that that was bad practice. That i should use async sockets instead? But i want my server to run on linux too, and isnt async win32 spesific? Hope some of you got anything usefull out of this and can point me in the right direction? Basically I''d like to know: How is the best way to write a turn based game, with lots of clients, and where some of the clients depend on eachother (i.e. its not ONLY turnbased). Thanks! Tor Arne

This topic is closed to new replies.

Advertisement