Developing secure and fault tolerant server

I started writing a poker game and i have to develop some kind of central server which will deal with all tables…

Anyway thats not so important…whats more important is that client(poker table) and central server need to be really reliable-in case that one goes down, other must be used to restore state etc…Also i have to deal with reliable transactions between the 2.Basically, since its a poker game, i must avoid data(money ;)) losses whenever possible…

I have some ideas and i have alrdy implemented some, but i think that i m reinventing the wheel here, so i could use some tips…any links, tutorials, books on the topic?
Tnx in advance peeps.

Well one of the first things to do right is correct shuffling. In short:

// how not to shuffle
for (i is 1 to n)
    Swap i with random position between 1 and n
// how to shuffle
for (k is 1 to n)
    Swap kwith random position between k and n

Notice that the first version selects a random number between 1 and n, the second between k and n. The former will produce uneven odds of some combinations, even with n as low as 3!

It also suggests what not to use for random number generation!!!

What you are looking for is a transactional database system that supports redundancy for up-time etc.

As far a servers go: the Java servers you implement connect to the database system. For the Java servers you don’t have to worry too much about up-time. You have multiple server that can take over if one fails. The database system is where you worry about up-time, transactions, etc…

@kingaschi
Indeed, i was looking for that term :slight_smile:

Well i know all that…i m just interested in some resources about building such a thing…I m able to create it, but i guess that there are some know hows…and googling wasnt so nice to me…

Tnx.

Warning: this is all just my theory, didn’t ever wrote or planned something similar
hmm… if server goes down during calculations for win/lose then you can’t do nothing about it except ignore last calculation, right?

For example, client send that he bet on red at roulette. Server receives his input and his action would be:

  1. mark start
  2. take away money from account
  3. calculate win/lose
  4. add money to account if it’s a win
  5. send new status to client
  6. mark end

let’s say for security reasons you have 2 databases, so if server goes down you won’t be able to connect to it. Then client app connects to backup server and backup server checks if last calculations were successfully completed (end is marked). If they are not, then I would restore account status from backup database, thus ignoring last game. Just a theory… :slight_smile:

I would suggest writing J2EE java beans for your server-side code. Once you’ve made an application in the form of an .ear-file, you can deploy it to any J2EE server (WebLogic, WebSphere, WebSphere Community Edition, Geronimo, JBoss, …). Your Application server, together with a good transactional database (Oracle, Oracle Express, MS SQLServer, … don’t know about MySQL) will take care of all the redundancy and fail-over issues.

Your client could be a J2EE client application (also wrapped inside an .ear-file), or it could be a regular java application (inside a .jar, for example) that uses IIOP to talk to the application server.

Warning: if you’ve never written a J2EE application before, the learning curve might be a little steep. But you get all the advantages almost for free, like transactional behavior, portability, scalability, redundancy, fail-over, database-independence, resource pooling, and whatnot. Take a look at the J2EE tutorials from Sun, they might give you an idea.

doesn’t sound like very exotic requirements to me tbh.

there are many ways to active them.

Reliable can me many things, judging from what you’ve said I actually think you mean integrity (data integrity/ relational integrity). build your finitive state machine and decide what should happen in every case given that things don’t add up and protect against it.

if you want to bold stuff down without heavily tangled code I would suggest having a look at aspect orientated programming, doesn’t matter if you go the lightweight or heavyweight approach.

If the client goes down then typically they will be defaulted to either check/fold, or whatever automation they selected for that turn. If the server goes down then you wouldn’t really continue where you left off because most people would have gone to other rooms and just probably will not be coming back on at the same time. So if that happens then just undo the transactions of that game!

Real money involved?

Yup, real money…

@Mr_Light
I ll check out the aspect orientated programming.

Tnx for the tips ppl.