I'm writing 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?
4 Answers
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).

- 26,463
- 15
- 97
- 154
-
Thanks! I will give a look! PS: In my question I wanted to ask if there's a technology alternative to AJAX to avoid polling. Maybe I was misunderstood. :) – Davide Jun 19 '11 at 19:18
-
Why does Comet use polling underneath? I thought it just held a connection open and used that to send data - where would the polling come in there? – Voo Jun 19 '11 at 19:28
-
-
@Thorbjørn Ah ok yeah in that case you have to detect that and open a new connection, sure. Personally when I think of "polling" in that context I understand a request in regular timesteps, but I assume that falls under polling as well. – Voo Jun 19 '11 at 21:25
-
@Voo, problem is that the server need to send information to the client at will, but the client must initiate the connection. – Thorbjørn Ravn Andersen Jun 19 '11 at 21:26
-
What about using XMPP protocol with OpenFire Server and Smack Framework? Maybe XMPP is useful for implementing server initiated communications... – Davide Jun 20 '11 at 12:08
-
I don't know much about XMPP so I can't comment. You might want to open a separate question on this topic. – mindas Jun 20 '11 at 12:33
I can suggest two main techniques.
The server has a method getUpdates, callable by clients. The method returns the control to the client when there is an update to show.
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.

- 1,367
- 7
- 25
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).