views:

132

answers:

2

In short I'm creating a socket server so I can add multiplayer support to my Flash game (Using Actionscript 3.0 Binary Socket on the Client-End).

I decided to go with Python since I'm the sole developer of the game/server and this will be my first non-blocking socket server. I was going to use Twisted but I deiced that I would use Python's asyncore (Asynchronous socket handler).

If I'm not mistaken connecting to a traditional database is a Blocking process. Since I'm trying to make this a non-blocking server I'm curious as to what solutions might be available to save permanent game related data?

+2  A: 

I suggest you use any DB you like (sqlite comes with Python and will probably serve you well!): just have a dedicated thread that accesses said DB, taking requests from a Queue (and using another Queue, passed in as part of the request, to return results if needed). Threads aren't so bad if you have a small number, and they never share access to any structure or system that isn't read-only, communicating only by queues (which are intrinsically thread-safe).

Alex Martelli
+1 You make it hard for anyone else to answer questions around here ;)
chrispy
@chrispy, tx, but an overbid -- the _vast_ majority of questions does get answered by somebody else!-)
Alex Martelli
Thanks Alex, I will look into Queue (never used it before)
CodeJustin.com
@CodeJustin, you're welcome -- Queue's a godsend (and the new Go language's "channels" somewhat reminiscent of it... it all goes back to Hoare's great old "CSP"!-).
Alex Martelli
+1  A: 

Blocking (in traditional database terms, it's "locking") is inevitable if you want any form of consistency in your data.

Consistency as in "it is impossible for two gamers with distinct scores to both be declared as the winner".

Reducing the locking to a minimum is precisely one of those things in database design that turn it into an art form you (perhaps alas) only get to master after having screwed up so many times.

Erwin Smout
Ahh, gotcha. Never thought of it that way, seen that Twisted somehow handles this by using a callback function but that kind of thinking is beyond my scope at the moment (struggling with all this server-side logic already, haha).
CodeJustin.com