我应该如何架构我的DB&安培;一转的API基于服务器的多人iPhone棋盘游戏? (思考的NodeJS,蒙戈,沙发等) [英] How should I architect my DB & API server for a turn based multiplayer iPhone board game? (thinking about nodejs, mongo, couch, etc)

查看:110
本文介绍了我应该如何架构我的DB&安培;一转的API基于服务器的多人iPhone棋盘游戏? (思考的NodeJS,蒙戈,沙发等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个回合的棋盘游戏为iPhone和Android的最终。我使用Appcelerator的钛开发它。我的多人游戏设计类似于词与朋友。准备当用户轮流,然后对手的游戏板相应的更新。

我的一个需求是有一个消息API使2玩家的设备更新彼此在游戏板上的移动后的状态。使用JSON这样做的,保持一个JSON对象,其中包含所有游戏板件在任何特定时间的位置,在设备上的思考。这是将需要更新本地设备上,然后一招作出后发送一个改变对手的设备的对象。

我在过去所做的API,用于移动平台和与MySQL这样做,我用PHP和发送JSON来回API服务器和移动设备之间。工作只是花花公子低并发用户,一般非大面积应用。我们也希望这个人会获得海量;)

所以,现在,而不是一般的httpd服务器之类的,我开始思考持久的插座和如果他们需要或不为我的新游戏。我也在想,这可能是聪明的放弃大LAMP堆栈,以及可扩展性,也许缓解的发展,以更倾向于的类似蒙戈/沙发数据流 - > Node.js的 - > iPhone。我会说实话,那将是我首次涉足非SQL数据库和Node.js的为好。

兴趣听别人的需要和经验这一点,更多的选择/想法,无论是我的想法是正确的方式,或者只是为自己创造头痛。


解决方案

首先,是的NodeJS真棒写反向TCP代理来NoSQL数据库。你可以让所有的标准命令通过,但修改/用自己的魔力,例如延长其API使得MongoDB的讲HTTP或CouchDB的插座上说话二进制协议。

当谈到选择一个NoSQL的解决方案,用于存储棋子和监测球员的动作,我认为无论是Redis的和CouchDB的是最好的人选。


  1. CouchDB的。它快速,可靠,并且可以处理大量并发的HTTP连接。这可能是最好的选择,因为不同的Redis它可以当广播消息的文档更改。该连续变化的API 使得它超级简单的你有每个玩家的应用程序监视器更改自己的董事会。请求可能是这样的:


    卷曲\"$HOST/dbname/_changes?filter=app/gameboard&feed=continuous&gameid=38934&heartbeat=1000
    Each客户会收到每行一个JSON对象,在响应随时随地一项相关文件被改变。 (和空白换行符每1000毫秒作为一种存活的。)


  2. Redis的。它使用一个简单的基于行的协议(如Memcached的++),谈谈插座,允许你存储列表,集合,任意哈希 - 甚至是二进制 - 值。这是非常快的,因为一切都发生在内存中,但保存在磁盘异步。但最重要的,你应该,因为它已经有 PubSub的通知的出炉评估。<强>请注意,您必须明确公布的举动通知了球员共用一个信道,因为Redis的不会自动发布一个键/值更改时。

由于MongoDB中没有观察变化 - 他们-发生的或做的pubsub我不认为这是一个不错的选择,虽然是额外的努力,你可以使它发挥作用的机制。

因此​​得出结论,您可以更换扩展他们已经提供到的东西适合你的游戏API的大LAMP栈使用CouchDB独自一人,Redis的独自一人,或任何一个放置在一个节点的应用程序背后过滤/。

祝你好运!

I'm working on a turn based board game for iPhone and eventually Android. I'm using Appcelerator Titanium to develop it. My multiplayer design is similar to Words With Friends. Users take turns when ready, and then the opponent's game board is updated accordingly.

One of my needs is to have a messaging API which enables the 2 players' devices to update one another on the status of the game board after a move. Thinking of doing this with JSON and keeping a JSON object on the device which contains the location of all game board pieces at any given time. This is the object that will need to update on the local device and then send a change to the opponent's device after a move is made.

I've done APIs in the past for mobile platforms and to do so I've used PHP with MySQL and sent JSON back and forth between the API server and the mobile device. Works just dandy for low concurrent users, and generally non-massive apps. Here's to hoping this one will get massive ;)

So now, instead of a general httpd server and the like, I'm starting to think about persistent sockets and if they're needed or not for my new game. I'm also thinking that it might be smart to forgo the big LAMP stack, and for scalability and maybe ease of development, to lean more towards a data flow of something like Mongo/Couch -> node.js -> iPhone. I'll be honest, it would be my first foray into a non-sql db and node.js as well.

Interested to hear others' takes and experiences on this, more options/thoughts, and whether I am thinking about it the right way, or just creating headaches for myself.

解决方案

First of all, Nodejs is awesome for writing reverse TCP proxies to NoSQL databases. You could let all the standard commands pass through but alter/extend their APIs with your own magic, e.g. making MongoDB speak HTTP or CouchDB speak a binary protocol over sockets.

When it comes to choosing a NoSQL solution for storing board game pieces and monitoring for player moves I think either Redis and CouchDB are the best candidates.

  1. CouchDB. It's fast, reliable, and can handle a lot of concurrent HTTP connections. It's probably the best option because unlike Redis it can broadcast a message when a document changes. The continous changes API makes it super simple for you to have each player's app monitor for changes to their board. The request might look like:

    curl "$HOST/dbname/_changes?filter=app/gameboard&feed=continuous&gameid=38934&heartbeat=1000


    Each client will receive a JSON object per line in the response anytime a pertinent document is changed. (And a blank newline every 1000ms as a sort of keepalive.)

  2. Redis. It uses a simple line-based protocol (like MemcacheD++) to talk over a socket and allows you to store Lists, Sets, Hashes with arbitrary--even binary--values. It's very fast because everything happens in memory but is persisted to disk asynchronously. But most of all you should evaluate it because it already has PubSub notifications baked in. Note that you'll have to explicitly publish move notifications over a channel the players share because Redis won't automatically publish when a key/value changes.

Since MongoDB does not have a mechanism for observing changes as-they-happen or doing pubsub I don't consider it a good option, though with extra effort you could make it work.

So to conclude, you may be able to replace "the big LAMP stack" with CouchDB alone, Redis alone, or either one placed behind a node app for filtering/extending the APIs they already provide into something that fits your game.

Best of luck!

这篇关于我应该如何架构我的DB&安培;一转的API基于服务器的多人iPhone棋盘游戏? (思考的NodeJS,蒙戈,沙发等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆