开发者

Multiplayer game in Java. What's the best solution?

I'm writing开发者_如何学JAVA a multiplayer/multiroom game (Hearts) in java, using RMI and a centralized server. But there's a problem: RMI Callbacks will not work beacause clients are Natted and Firewalled. I basically need the server to push data updates to clients, possibly without using polling and without using sockets (I would code at an higher level) In your opinion, what's the best solution for realizing this kind of architecture? Is an ajax application the only solution?


You say that you don't want polling, but AJAX is exactly that. You can look at Comet but it's hard to escape polling anyway (e.g. Comet itself uses polling underneath).


You could use a peer to peer framework such as JXTA.


I can suggest two main techniques.

  1. The server has a method getUpdates, callable by clients. The method returns the control to the client when there is an update to show.

  2. When Clients perform the registration, they give the server a callback remote object Since this object is not registered in any rmi registry, there should no be any issue with natted clients.


I'm not sure how(if) ajax works for a non-browser-based app. You could just maintain your own pool of SocketConnections open for the duration of the application with a Thread per connection.

If you need to scale to a lot of concurrent connections, look to a non-blocking I/O framework like Apache Mina or Netty (related SO post: Netty vs Apache MINA).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜