Sign in to follow this  
Eralp

Online poker game

Recommended Posts

Hello, I am currently planning on coding an online poker game with only javascript frontend, and use ajax to send updates to server, and a page like callback.html which client will open and see if there is any update it should process.

The thing is I am confused about the server part, I generally develop desktop applications and there I could create many game classes and call their functions when needed, this feels natural, but with a technology like PHP or ASP.NET how should I code it?

There are two ways in my mind, make the web pages act like a router, run a dedicated server and when client sends AJAX request to webpages, simply open a new TCP socket and push that data to actual game server. But this will basically double the request times. ( I don't know it its negligible or not )

Other way is save every game table to database and when ajax update comes to say table 5, fetch the table 5 from the database, load the data to dynamic "table" class and call the functions like normal desktop application and when everything is done save the new state of the table to database. The drawback of this is that I need to make many database queries.

So which one is a better solution do you think? Or is there a better option I couldn't think of?

Thanks.

Share this post


Link to post
Share on other sites
[quote name='Eralp' timestamp='1312502627' post='4844788']
Other way is save every game table to database and when ajax update comes to say table 5, fetch the table 5 from the database, load the data to dynamic "table" class and call the functions like normal desktop application and when everything is done save the new state of the table to database. The drawback of this is that I need to make many database queries.
[/quote]

You want active game instances to live on some server that supports long-lived HTTP requests. You can use double-buffered long-polling XHR Ajax/Ajaj requests (COMET style) or use a document with chunked transfer encoding that keeps pushing small script tags to be executed. I recommend the former :-)

The game rules should be enforced on the server, and the players need to talk to each other. Talking through a database will scale very, very poorly. Instead, you want to either use some kind of subscribing message queue, or an in-core web framework like Python/Twisted or node.js to serve game rooms.

The XHR handler will look something like:

wait (for second request to come in from same user or max 10 seconds)
wait (for data to become available or max 10 seconds)
return data

Share this post


Link to post
Share on other sites
Thanks for the information :)

How about storing nearly everything in Application[] map? Can I adjust their lifetime if I buy a regular webhosting?(not dedicated server) or can I refresh the variables so that they are not lost?

What are the drawbacks of this method,or is it the worst thing I can do to my hosting ^^ because I know they are not created to be used like that.

I am talking about maximum 1000 concurrent users, which makes approx 200 games, 100 kb per game should be enough and that makes roughly 20 mb space. I don't have scalability in my mind, I hope I won't regret that :)

Share this post


Link to post
Share on other sites
[quote name='Eralp' timestamp='1312574725' post='4845191']
How about storing nearly everything in Application[] map? Can I adjust their lifetime if I buy a regular webhosting?(not dedicated server) or can I refresh the variables so that they are not lost?

What are the drawbacks of this method,or is it the worst thing I can do to my hosting ^^ because I know they are not created to be used like that.

I am talking about maximum 1000 concurrent users, which makes approx 200 games, 100 kb per game should be enough and that makes roughly 20 mb space. I don't have scalability in my mind, I hope I won't regret that :)
[/quote]


For any kind of gambling app, even if you don't give money out yourself, of bigger concern is regulation. If you don't already have a lawyer, discuss your project with a business lawyer before going much farther. Also you'll want to verify with your hosting company, since several major hosts forbid any form of gambling applications even if no money is involved.



For that few players a database should be fine, assuming you are smart about what you are doing.

A simple LAMP configuration can support a few thousand transactions per second.

But you can also write queries that take several seconds, or even several minutes, to complete. That is an implementation detail which you can control.


Nothing you've written pushes me toward any particular option, any persistent communications channel should be able to handle it, and the memory requirements are minimal. Then it just comes down to you being smart about what you process and transmit.


You'll still need to be careful with your design and implementation to ensure validity to avoid cheaters. That means validating all input, ensuring each client only gets the information it needs to play the game, and isn't leaked information about other player's cards, cards still in the deck, or other exploitable information.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this