java 超级简单的 XMPP 服务器或对简单自定义 Openfire 组件的建议
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2420669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Super simple XMPP server or advice for a simple custom Openfire component
提问by gav
I need a server to send and recieve XMPP messages from Android clients running a multiplayer game I'm writing. I picked XMPP because I don't want to long poll and Sockets can be an issue over the cellular network (Carriers may block them).
我需要一个服务器来发送和接收来自运行我正在编写的多人游戏的 Android 客户端的 XMPP 消息。我选择 XMPP 是因为我不想长时间轮询并且套接字可能是蜂窝网络上的一个问题(运营商可能会阻止它们)。
I have been looking at OpenFirewhilst it sounds amazing, I don't need an admin panel Voice Chat, Chat Rooms etc. it seems very heavyweight and geared towards a chat solution for businesses when all I need is to match players and pass their moves to each other recording a score at the end. Is there a stripped down version of OpenFire so I can just register one component which will service all requests? Regarding adaptation with openfire I can't find a clear example of adding a custom component to perform a similar task.
我一直在看OpenFire,虽然它听起来很棒,但我不需要管理面板语音聊天、聊天室等。它看起来非常重量级,适合企业的聊天解决方案,当我只需要匹配玩家并通过他们的动作时最后互相记录分数。是否有精简版的 OpenFire,所以我可以只注册一个可以为所有请求提供服务的组件?关于与 openfire 的适配,我找不到添加自定义组件来执行类似任务的明确示例。
What I need is a library or existing simple server which I can run and register my custom message listener to. I just need to be able to service any requests coming in and respond appropriately. I'm hoping that I don't have to write the thread management as that issue is common to a typical chat server but I do need to write the code to interpret and respond to the messages sent.
我需要的是一个库或现有的简单服务器,我可以运行和注册我的自定义消息侦听器。我只需要能够处理传入的任何请求并做出适当的响应。我希望我不必编写线程管理,因为该问题在典型的聊天服务器中很常见,但我确实需要编写代码来解释和响应发送的消息。
I hope this makes sense, anyone who has written such a piece of server code I would love an example. For those of you that haven't tried it but have an idea how you would start please chip in too! The more detail the better.
我希望这是有道理的,任何写过这样一段服务器代码的人都会喜欢一个例子。对于那些还没有尝试过但知道如何开始的人,请也参与进来!越详细越好。
Thanks in advance,
提前致谢,
Gav
加夫
采纳答案by Christopher Orr
You can use almost any XMPP server; I know that Openfire will work, or I've also recently used Prosodywhich is very lightweight and easy to install (on Linux).
您几乎可以使用任何 XMPP 服务器;我知道 Openfire 可以工作,或者我最近还使用了Prosody,它非常轻巧且易于安装(在 Linux 上)。
What you want is a standalone component that communicates with your XMPP server (and thereby can reach your users) using the XMPP component protocol. That's where the game intelligence lies.
您需要的是一个独立的组件,它使用XMPP 组件协议与您的 XMPP 服务器进行通信(从而可以访问您的用户)。这就是游戏智能所在。
See my previous answer to a very similar question for more detail:
XMPP C# Interaction
有关更多详细信息,请参阅我之前对一个非常相似问题的回答:
XMPP C# Interaction
Another great place to look for information is anything written by Hyman Moffitt, who created chesspark.com (since purchased by chess.com so not available) — a site that matched chess users and controlled games using XMPP.
另一个寻找信息的好地方是Hyman Moffitt所写的任何内容,他创建了 chesspark.com(由于已被 chess.com 购买,因此不可用)——一个使用 XMPP 匹配国际象棋用户和控制游戏的站点。
See this blog post as a start:
http://metaHyman.im/2008/11/21/chesspark_design_details_part_1_why_xmpp/
请参阅此博客文章作为开始:http:
//metaHyman.im/2008/11/21/chesspark_design_details_part_1_why_xmpp/
回答by Joe Hildebrand
If you want a fast, lightweight XMPP server, try Prosody. The other answers are right, however, in that you'll want to look at PubSubfirst, then writing your own component, before adding functionality directly to the server.
如果您想要一个快速、轻量级的 XMPP 服务器,请尝试Prosody。但是,其他答案是正确的,因为您需要先查看PubSub,然后编写自己的组件,然后再将功能直接添加到服务器。
回答by Robin
You should be able to accomplish this with OpenFire (or other XMPP servers) out of the box if they support pubsub. Not sure of the specifics of your needs, but I would think that Personal Eventing Protocolor its superset PubSubshould be able to handle your use case. OpenFire does support both these protocols.
如果 OpenFire(或其他 XMPP 服务器)支持 pubsub,您应该能够立即使用它们来完成此操作。不确定您的具体需求,但我认为Personal Eventing Protocol或其超集PubSub应该能够处理您的用例。OpenFire 确实支持这两种协议。
If these do not support your use case, then a custom pluginis pretty easy to write.
如果这些不支持您的用例,那么自定义插件很容易编写。
As for the heavyweight or lightweight, unless you have some specifically small environment for running the server, I doubt it will matter. You simply won't be using many of the features that exist.
至于重量级或轻量级,除非你有一些特别小的环境来运行服务器,否则我怀疑这是否重要。您根本不会使用现有的许多功能。
I have used XMPP pubsub for clients to communicate actions to each other so users can get live updates of what coworkers in a group are working on.
我已经使用 XMPP pubsub 让客户端相互交流操作,以便用户可以实时更新组中的同事正在做什么。

