tags:

views:

68

answers:

1

Hello,

I have a multiplayer card game (up to 4 players can play the same instance of the game) up on facebook. The game is small and is hosted on a single server. I am now looking into scalability as I am hoping that soon one server won't be enough.

The server stores in Memory a list of all games which are underway: List<Game>

When a client makes a request (for example throws a card) it POSTs a message to the server. Now here comes the tricky part. The server does not send the response immediately but rather keeps checking if any other player has modified the game state before it replies. This approach works very well because the client (silverlight) is not constantly polling the server.

What approach would you recommend I take in Azure? My main priority is getting a fast response to the clients and avoiding the constant polling from the client.

With my limited Azure knowledge I am thinking of taking this road:

Store the games in azure table storage instead of in memory.

This will be done in the webrole: PSEUDOCODE:

void Page_LoadOfAnAspxPage
{
 // deserialze the message from the posted information
 Message msgClient = ...;

 // retrieve game from table storage
 Game g = RetrieveFromTableStorage(gameGuid);

 // post message to game
 g.ProcessClientMessage(msgClient);

 // save back to table storage so other game clients can be aware of new state
 SaveToTableStorage(gameGuid, g);

 // now wait until another client modifies the game
 while(true)  // will I be incurring hosting charges (transactions for what is going on in this while loop)???
 {
  // grab game from table storage
  g = RetrieveFromTableStorage(gameGuid);

  // has something changed?
  MsgResponse response = g.ProcessClientMessage(msgClient);
  if (response.ActionName != ActionName.GameHasNotChanged)
  {
   // some other client changed the game.
   // give this response back to our client
   break;  
  }
  // sleep a little and check again...
  Sleep(xx);
 } 
}

Do you believe this approach will work? Any roadblocks I might run into? I would be really grateful for any suggestions/improvements.

Thank you!

santiago

A: 

Look into Silverlight Duplex capability. That will distribute the load/computing power to the silverlight clients and not on the server, without having you to manage your own polling mechanism.

You can then host the logic in the webrole in the form of a WCF service

http://silverlightforbusiness.net/2009/06/23/pushing-data-from-the-server-to-silverlight-3-using-a-duplex-wcf-service/

ronaldwidha