我应该为基于浏览器的实时游戏选择AMQP或XMPP哪一个? [英] Which one should I choose AMQP or XMPP for real-time browser-based game?

查看:102
本文介绍了我应该为基于浏览器的实时游戏选择AMQP或XMPP哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为基于浏览器的无Flash JavaScript实时回合制游戏选择AMQP(RabbitMQ)与XMPP(eJabberd)之间.我对AMQP和XMPP协议了解不多.我想使用PHP进行用户授权,并使用MySQL进行一些数据存储检索.据我了解,RabbitMQ有PHP客户端,而eJabberd没有.

I'm choosing between AMQP (RabbitMQ) vs XMPP (eJabberd) for my browser-based flash-free javascript powered real-time turn-based game. I don't know much about AMQP and XMPP protocol. I would like to use PHP for user-authorization and some data store-retrieve with MySQL. As far as I found out, RabbitMQ has PHP clients but eJabberd not.

我了解的是javascript客户端调用PHP脚本并操纵必要的处理,然后传递给AMQP或XMPP服务器,以将数据传递给对手玩家.有来自Wrox的不错的书《使用JS和jQuery进行Pro XMPP编程》,但是没有关于PHP的示例.因此,以下是我的问题.

What I understood is javascript client calls PHP script and manipulate necessary processing and then pass to AMQP or XMPP server to pass the data to opponent player. There is a good book 'Pro XMPP Programming with JS and jQuery' from Wrox but there is no example with PHP. So following are my questions.

1)哪种协议适合我的游戏?

1) Which protocol is suit for my game?

2)我是否仅因为它的PHP客户端支持而选择RabbitMQ?

2) Shall I choose RabbitMQ just for it's PHP client support?

推荐答案

通过在XMPP BOSH上使用HTTP绑定方法,我在Java脚本中实现XMPP客户端取得了相当不错的成功.我不了解AMQP,但是对于客户端访问,我喜欢XMPP.几句话为什么.

I've had fairly good success implementing an XMPP client in Javascript by using HTTP Bind approach to XMPP BOSH. I don't know about AMQP, but for client-side access, I love XMPP. A few words why.

ejabberd已经包含了BOSH支持,并且要与Javascript(可能是Flash)一起使用,您只需要指示服务器将请求重定向到配置ejabberd的端口即可侦听HTTP请求. (而且这仅仅是因为当今浏览器中的Javascript安全模型禁止Javascript请求到不同的域甚至是不同的端口.)

ejabberd already includes BOSH support, and to use with Javascript (and presumably Flash) you just need to direct your server to redirect requests to port on which you configure ejabberd to listen for HTTP requests. (And even this only because Javascript security model in today's browsers forbids Javascript requests to different domains and even different ports.)

由于XMPP是一堆相当琐碎的小型XML文档,因此以您选择的任何语言对它们进行编码应该相当容易.

Since XMPP is a bunch of quite trivial small XML documents, it should be fairly easy to encode them in any language you pick.

由于得到了广泛的支持,因此您可以避免要求用户向您的服务进行注册,他们将对此表示肯定的感谢.

Since it's widely supported, you might be able to avoid requiring your users to register with your service, which they will most certainly appreciate.

实施XMPP意味着您可以轻松地为游戏添加即时消息支持,并与Jabber网络的其余部分(包括Google Talk)联合.

Implementing XMPP means you can trivially add instant messaging support to your game, with federationing to the rest of the Jabber network (including Google Talk).

由于我对AMQP一无所知,因此无法进行比较-但我可以说为什么我总是在以后的多人游戏项目中始终优先考虑使用XMPP.

Since I don't know anything about AMQP, I cannot compare them -- but I can say why I'll always first consider XMPP for my future multiplayer projects.

我选择ejabberd的个人原因很简单-在Debian上安装和配置超级简单.我几乎完全不熟悉Erlang和Java.但是我对Erlang的了解是,它使可扩展性易于实现,并且ejabberd人们说他们已经实现了.

My personal reason for choosing ejabberd is simple -- it's super easy to install and configure on Debian. I'm almost completely unfamiliar with Erlang and Java; what I understand, however, about Erlang is that it makes scalability easy to achieve, and ejabberd people say they have achieved it.

如果您想进行服务器端逻辑检查,恐怕我不知道有什么好的方法.我将使用一个代理PHP脚本对传入的XMPP BOSH消息进行完整性检查,然后将其转发到服务器,而不仅仅是通过Apache的mod_rewrite转发.

If you want to do server side logic checking, I'm afraid I don't know of any good method. I'd go with a proxy PHP script doing sanity checking on the incoming XMPP BOSH message, then forwarding it to the server, instead of just forwarding it via Apache's mod_rewrite.

如上所述,您肯定必须进行某种代理(使用mod_rewrite或PHP或其他方式),因为XMPP服务器将侦听与主" Web服务器不同的端口,并且Javascript跨域安全性模型不允许在其他端口上执行XMLHTTPRequest.

As mentioned above, you will definitely have to do proxying of some sort (with mod_rewrite or with PHP or in some other way) since the XMPP server will listen on a different port than the "main" web server, and Javascript cross-domain security model does not allow doing XMLHTTPRequest on a different port.

因此,在将BOSH请求中继到您选择的XMPP服务器时,进行完整性检查可能是最容易的.深入研究服务器软件可能不是进行此类检查的最佳方法.这将花费很长时间,并且可能会使其与游戏其余部分的集成变得更加困难.

So, sanity checking might be easiest done while relaying BOSH requests to XMPP server of your choice. Digging into the server software might not be the best way to do this type of checks. It would take long, and would probably make it harder to integrate with the rest of your game.

或者,我偶然发现了一个提到 XMPP组件和ejabberd模块的答案.这对我来说也是一个有趣的阅读.

Alternatively, I stumbled upon an answer that mentions XMPP components and ejabberd modules. This will be an interesting read for me, too.

祝你好运,完成后一定要在游戏名称旁添加评论-我很想看到它:-)

Good luck, and be sure to drop a comment with the name of the game when it's done -- I'd love to see it :-)

我刚刚注意到其他人发布了非常类似的问题送给您.它的答案为您提供了一些更有趣的信息.

I just noticed someone else posted a very similar question to yours. Its answers contain some more interesting info for you.

在Flash上​​使用XMPP:

On using XMPP with Flash:

尽管如此,您仍可以将HTTP绑定(BOSH)与Flash结合使用.实际上,尽管HTTP绑定允许Javascript访问XMPP,但是它是为各种应用程序设计的,例如经常会中断的移动连接.

You could nevertheless use HTTP binding (BOSH) with Flash. In fact, while HTTP binding allows Javascript to access XMPP, it was conceived for a variety of applications, such as mobile connections that can often break.

我主要通过观察基于Web的客户端JWChat和ejabberd之间的通信(有关BOSH的信息),然后跨平台客户端Psi和ejabberd之间的通信(有关协议本身的信息),来弄清楚如何建立连接.借助JWChat和WebKit的Web Inspector或适用于Firefox的Firebug,人们可以轻松地跟踪向服务器发送的XMLHttpRequests.使用Psi,可以打开XML控制台并读取通信日志.结合使用您选择的语言对客户进行原型制作,学习BOSH和XMPP变得非常容易.

I mostly figured out how to establish the connection by observing communications between web-based client JWChat and ejabberd (for info on BOSH), and then communications between cross-platform client Psi and ejabberd (for info on protocol itself). With JWChat and WebKit's Web Inspector or with Firebug for Firefox, one can easily track XMLHttpRequests being done towards the server. With Psi, one can turn on the XML console and read the communications log. Combined with prototyping a client in a language of your choice, studying BOSH and XMPP turned out to be very easy.

此外,以下XEP很有用: XEP-0124 XEP-0206 .

Also, following XEPs are useful: XEP-0124, XEP-0206.

我正在阅读的O'Reilly书,"XMPP:权威指南" (P. Saint-Andre,Kevin Smith,RemkoTronçon;便宜得多在Apple的App Store中)还使您有为什么要按原样完成事情"的感觉,并记录了XMPP的许多小内容和各种应用程序.

O'Reilly book that I'm reading right now, "XMPP: The Definitive Guide" (P. Saint-Andre, Kevin Smith, Remko Tronçon; much cheaper on Apple's App Store) also gives you the feeling "why things are done the way they are", and documents many small things and various applications of XMPP.

在那之后,实现基于BOSH的客户端可能会变得非常容易.除了使按钮播放和暂停外,我没有Flash编码方面的经验,因此请耐心等待:-)

After that, implementing a BOSH-based client could turn out to be rather easy. I have no experience with coding with Flash apart from making a button play and pause, so take this with a grain of salt :-)

这篇关于我应该为基于浏览器的实时游戏选择AMQP或XMPP哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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