JAVA push from server to clients

benji picture benji · Mar 27, 2012 · Viewed 8.3k times · Source

I would like to have the clients query each other through the server without delay ( = no polling interval ).

Example: Server S, clients A and B

Client A wants to request Client B. Client A will make a request to the server S, no problem there. Then Server S needs to be able to request Client B but how to do that without polling?

All the node.js/APE (for PHP) technos are designed for the web, however I don't use a web server for that. Does Java has something close to a push technology/framework that is not web?

I would really prefer a solution that doesn't require each client to use their own reserved port (I don't want to end up with 1 WebService per client for example)

Note: all the clients are on the same machine.

Answer

user507484 picture user507484 · Mar 27, 2012

A couple of options...

  • Plain socket communication. java.net.Socket, java.net.ServerSocket. Maximum flexibility but requires knowledge of low level TCP/IP API/concepts.

  • The good old RMI. Java based RPC layer on top of TCP/IP. Works good when client and server are both in Java and generally in same subnet. May give problems when client and/or server are natted.

  • Spring Remoting, it's actually pretty decent.

  • Bi-Directional Web Services. i.e. clients host their own WSes which the Server calls when it needs to do a callback.

  • JMS as someone already mentioned.

  • Distributed Data Structures, Check out http://www.hazelcast.com/

Lots of options to chose from, no need for webserver.