代码之家  ›  专栏  ›  技术社区  ›  santiagoIT

Azure:关于使简单的多人纸牌游戏可扩展的建议

  •  0
  • santiagoIT  · 技术社区  · 16 年前

    我在facebook上有一个多人纸牌游戏(最多4个玩家可以玩同一个游戏实例)。 我现在正在研究可伸缩性,因为我希望很快一台服务器就不够了。

    服务器在内存中存储正在进行的所有游戏的列表: List<Game>

    当客户机发出请求(例如抛出一张卡)时,它会向服务器发送一条消息。 服务器不会立即发送响应,而是在响应之前不断检查是否有其他玩家修改了游戏状态。 这种方法工作得很好,因为客户端(silverlight)不经常轮询服务器。

    以我有限的知识,我想走这条路:

    这将在webrole中完成:

    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);
     } 
    }
    

    你相信这种方法行得通吗?我可能遇到什么障碍? 如有任何建议/改进,我将不胜感激。

    非常感谢。

    圣地亚哥

    1 回复  |  直到 16 年前
        1
  •  0
  •   ronaldwidha    16 年前

    查看Silverlight双工功能。这将把负载/计算能力分配给silverlight客户机,而不是服务器,而无需您管理自己的轮询机制。

    然后可以以WCF服务的形式在webrole中托管逻辑

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