4

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.

benji
  • 2,331
  • 6
  • 33
  • 62

3 Answers3

5

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.

  • - Plain socket communication: the reason I ask for a framework is that is it hard to invoke a remote method on a remote object where you're working at the level of sockets. - RMI / WS : they would require to have each client to use a pre-defined TCP port, that is no an option (I'll update the question, sorry for that) - JMS is still a delayed treatment of the request I think I'll check out your last link, thanks! – benji Mar 27 '12 at 22:01
  • You can programatically bring up a WS on a port determined at runtime, using the Endpoint.publis(*) API, and then call a WS on Server, to let server know of this endpoint URL. That way the client doesn't need to use a predefined port. –  Mar 27 '12 at 22:06
  • What is great in the TCP push technology is that you're gonna use a single TCP port for the server and then client side you will use ports that are in the "dynamic port range", and be sure you'll never conflict with anything on the machine! I wonder if it is possible to get and use such an ephemeral port or if those are strictly reserved to the TCP protocol. – benji Mar 27 '12 at 22:16
  • Spring remoting is just a wrapper over other existing protocols for remote access. Only wrappers over protocols that support some sort of messaging are actually appropriate to the use case, such as over JMS. Most are actually Request/Response based. – Robin Mar 27 '12 at 22:50
  • @BhaskarKarambelkar what i want to achieve is i have a jsp page displaying records on client Side and if the Server gets updated it should be reflected back to the client without refreshing the client page(server should push the data to client) using JAVA technology. Pls help me – Azuu Apr 08 '13 at 09:18
  • @Azuu, Google for websockets. –  Apr 10 '13 at 18:01
3

If you really don't want to use a web server then I would check out JMS. That being said, all the cool kids are using web servers these days since the protocols are so ubiquitous.

Pace
  • 41,875
  • 13
  • 113
  • 156
  • Ok, well let's say that the server is a web server that host a web service. Then how can he push to the clients ?(there is no javascript there, so no ajax or node.js etc) – benji Mar 27 '12 at 21:55
0

Your use case requires a messaging protocol. We don't really know the scope of your problem but you already said you want a server to exchange requests between clients, so I would go with an existing solution rather than a roll your own approach.

JMS has been mentioned and is certainly a viable Java based solution, another would be XMPP which is a real time communication protocol commonly used for instant messaging.

It is an open standard that has both server and client support in every major language and platform. This would allow you to have standalone apps, web based ones and apps for mobile devices all being able to communicate with each other. The only potential gotcha for your use case is that it is text based. Since you haven't said what requests you want to pass back and forth, I don't know if this will fit your bill or not.

You can use Smack for client side development in Java and any OS server you want.

Robin
  • 24,062
  • 5
  • 49
  • 58