title: RMI alternatives for bidirectional asynchronous calls and callbacks through firewalls or NAT
body: <p>I'm writing a server-client architecture based game in Java.</p>
  
  <p>For design reasons, I would like to use asynchronous calls for passing client actions to the server, and also asynchronous callbacks for passing the result(s) of said actions back to the client. Asynchronous calls allow buffering of client actions. Queued buffering allows simple, basically one threaded processing of client actions.</p>
  
  <p>At the moment, my server and client code is pretty symmetric. They create a registry, then export and bind themselves.</p>
  
  <p>Asynchronicity is achieved by buffering the incoming actions or results in a ConcurrentLinkedQueue. Actual processing is done by a thread running at regular intervals.</p>
  
  <p>However, this current architecture does not work when clients are firewalled or behind a NAT. In this case the server simply can not reach clients to push results to them.</p>
  
  <p>Furthermore, in this current architecture the server does not know which client sent a given action, unless a redundant layer of authentication or session handling is introduced. This allows forged actions and cheating.</p>
  
  <hr>
  
  <p>I've been thinking about possible solutions but haven't found a proper one:</p>
  
  <ul>
  <li><p>Client pull instead of server push. There could be a method on the server that the clients call periodically to fetch their results. However, this approach seems very ugly, it introduces additional delays, bandwidth and timing issues. Does not solve action forgery either. Direct notifications are also very much preferred.</p></li>
  <li><p>TCP connections by themselves allow bidirectional communication, and can definitely identify clients, so RMI or JRemoting <em>might</em> be hacked to support it, but I'm don't know how, and I'm not aware of any existing solution.</p></li>
  <li><p>Message passing. I'm not sure whether message passing frameworks support authentication / sessions or client identification. I'd definitely lose remote methods though.</p></li>
  <li><p>I believe the correct solution would be to find a remote method invocation framework that supports all of the above.</p></li>
  </ul>
  
  <hr>
  
  <p>So in a nutshell, I'm searching for a way to:</p>
  
  <ul>
  <li>call the server asynchronously or pass a message to it</li>
  <li>call the client asynchronously or pass a message to it, even behind firewall or NAT</li>
  <li>identify the client sending the action</li>
  <li>preferably be able to call methods, not just pass messages</li>
  <li>keep the ability to easily test it with JUnit and Mockito (multiple clients per machine)</li>
  </ul>
  
  <p>Are there any remote method invocation frameworks with support for these? Which is the best?</p>