1

For a web service application, I would like for the server to be able to notify the clients about some events. When a client is launched, he calls one of the WS methods to get some information it needs. Then the server, that stores this information, listens continuously for changes on these information and if there is a change, it notifies the concerned client.

I don't know if a web service is a good solution to my problem? I don't know how it may work concerning the TCP connections, since the server may notify a client after a very long time.

What would be the best architecture to solve this kind of issue?

Thanks


EDIT: I've looked at some discussions that propose to use Comet, but if you think there are simpler and more convenient solution, please let me know. Since I'm starting this project from scratch, I have no limitations.

I can also use a polling model where the clients periodically poll the server for the information they need, but then I need to take into account the load that this model may create on the server. I don't know if web services can support such a load when there are a lot of clients.

I've also looked at the asynchronous functionality provided by Servlet 3.0 but I don't know how it may solve my problem.

manash
  • 6,985
  • 12
  • 65
  • 125
  • Do you need to support IE? Otherwise, have you looked at server-sent events? http://stackoverflow.com/questions/9397528/server-sent-events-vs-polling – martijno Aug 20 '12 at 11:54

3 Answers3

0

Without polling: sockets

With polling and webservices: u should use etag (html).

When a client polls he sends a request with an etag. webservice responds either with 200(ok) and data or 304(not modified). 304 has no body => less trafic

Err
  • 291
  • 2
  • 13
0

Instead of client polling the server, you could implement a callback method on the client so that when ever server want to publish some changes to the client, the server can use the callback method provided by the client.

Sajan Chandran
  • 11,287
  • 3
  • 29
  • 38
  • Do I need my client to also have a web service in order to receive server notifications through the callback method? If yes, I think it is a complex solution since it involves now two web services, one on the server side and another on the client side. – manash Aug 21 '12 at 07:09
0

I can think of one the two approaches below using web services solution:

  1. Callback: When client invokes the server it leaves its call back url and a id, say correlation id. When the server wants to respond back to the client it will just use the call back url to notify. The Server can use a variety of approaches to process the request asynchronously. Your client need not be a webservice for this, but it should be capable of accepting requests (callback). It can be a servlet etc.

  2. Polling: When client makes a request to the server it receives back a id, say requestid. After specified interval client polls the server with this request id to fetch a response. A reasonable timeout and polling interval based on the processing time would be required.

techuser soma
  • 4,766
  • 5
  • 23
  • 43