开发者

Android P2P Multiplayer game (with a) XMPP/Google talk b) JXTA peerdroid c) other way)

开发者 https://www.devze.com 2022-12-22 03:03 出处:网络
I am an android developer and I made some board games. Now i want to make some of my board games multiplayer. I don\'t want to create and host my own web service, so i thought about P2P.

I am an android developer and I made some board games. Now i want to make some of my board games multiplayer. I don't want to create and host my own web service, so i thought about P2P.

The first thing i found was the XMPP protocol, however it's not real P2P, but if i can use the existing google talk service, i'm ready to go. Is this pos开发者_StackOverflow社区sible while using your existing google account without interfering with the normal working of your google talk client?

Then i heard about JXTA, a real P2P solution, and it's already ported from J2ME to Android (http://code.google.com/p/peerdroid/).

Maybe i am overcomplexing things here (as i do sometimes)

I just want to know the easiest way to do simple P2P for a boardgame.

All your opinions are welcome! Thanks in advance


Kristof, Did you get an answer to your question? I've been working on a multi-player application recently as well, though I've chosen to host the server (originally). I'm now reconsidering my choice, though, but the library I'm using fully supports peer to peer communications. The underlying protocol is built on top of Google Protobuf. It's essentially a full duplex RPC stack built on top of Netty, which can use Protobuf. Here's the URL to the RPC protobuf stack: http://code.google.com/p/protobuf-rpc-pro/

The author has been very helpful and I've found a couple of bugs, nothing major. I also had very little issues getting these libraries working on my Android phone, but they're not terribly "compact." Nothing extraordinarily large, just not small :). So far, I've had no issues getting the communications working both synchronously and asynchronously. As such, I may be moving my game over to a "peer to peer" style, and just provide the necessary location/registration server that would be used to find existing games/server.


Using XMMP should be possible for you case. Look at smack from igniterealtime. They have a nice and active java api that helps to build you own jabber extension packets that can be used to transport the changes in game state.

I think that using two google talk clients at the same time with the same account could be difficult. But it would be great because you could invite all the friends from you list to play with you directly from your game. This way you could easily get more people to play your game.


You can't use the existing Google Talk Service/Connection from what we've seen. You should take Janusz's advice and check out the smack library, that's your best bet. To allow multiple non-interfering connections with the same GTalk login take a look at the resource component of the XMPP address, it's what allows you to be logged into two clients at the same time to the same account. You can effectively make your game another client. More here: http://code.google.com/appengine/docs/java/xmpp/overview.html#JIDs_and_Resources

Finally, there appears to be some new functionality in 2.2 relating to device push communication, but I haven't looked into it yet. 2.2 is not widely deployed yet either, so probably of limited use.


Basicly, if you want to write a multi user game or a game built on top of XMPP (Jabber), you should have a serious look at pubsub extension of XMPP. It's designed for pushing data from a server to clients, in the opposite way of HTTP. In HTTP the client has to pull information from the server all the time to be able to know when some new data is pushed. While XMPP is designed to push data to clients, when something happens. Less resources used on server and clients.

You should not use the Chat part of XMPP, as that will interfere with the users presence.

In pubsub you can create a tree of nodes, where clients can listen to any new data published in any node or subnod in the tree that the client subscribes to. So if some client publish data on one node, all clients that has subscribed to that node, or any parent, will be notified about this data.

The good part with XMPP is that it's extensible so you can extend the protocol with your own extensions. I also give you user authorization, authentification and encryption, and you don't need to debug that yourself.

You could use any XMPP-server with good support for pubsub or you can host one server yourself. There are plenty of servers usable for this. GTalk doesn't have support for PubSub last time I looked.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号