简体   繁体   English

Web服务和服务器->客户端通知

[英]Web service and server->client notifications

For a web service application, I would like for the server to be able to notify the clients about some events. 对于Web服务应用程序,我希望服务器能够将某些事件通知客户端。 When a client is launched, he calls one of the WS methods to get some information it needs. 启动客户端时,他调用WS方法之一来获取其所需的一些信息。 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? 我不知道Web服务是否可以很好地解决我的问题? I don't know how it may work concerning the TCP connections, since the server may notify a client after a very long time. 我不知道它在TCP连接方面如何工作,因为服务器可能会在很长一段时间后通知客户端。

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. 编辑:我已经看过一些建议使用Comet的讨论,但是如果您认为有更简单,更方便的解决方案,请告诉我。 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. 我不知道当有很多客户端时,Web服务是否可以支持这样的负载。

I've also looked at the asynchronous functionality provided by Servlet 3.0 but I don't know how it may solve my problem. 我还研究了Servlet 3.0提供的异步功能,但我不知道它如何解决我的问题。

Without polling: sockets 不轮询:套接字

With polling and webservices: u should use etag (html). 使用轮询和Web服务:您应使用etag(html)。

When a client polls he sends a request with an etag. 客户进行轮询时,他发送带有etag的请求。 webservice responds either with 200(ok) and data or 304(not modified). webservice用200(ok)和数据或304(未修改)响应。 304 has no body => less trafic 304没有身体=>交通减少

您可以在客户端上实现回调方法,而不是客户端轮询服务器,以便在任何服务器要向客户端发布某些更改时,服务器都可以使用客户端提供的回调方法。

I can think of one the two approaches below using web services solution: 我可以想到以下使用Web服务解决方案的两种方法之一:

  1. Callback: When client invokes the server it leaves its call back url and a id, say correlation id. 回调:当客户端调用服务器时,它将留下其回调URL和一个ID,例如相关ID。 When the server wants to respond back to the client it will just use the call back url to notify. 当服务器想要响应客户端时,它将仅使用回调URL进行通知。 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). 您的客户端不必为此提供Web服务,但是它应该能够接受请求(回调)。 It can be a servlet etc. 它可以是servlet等。

  2. Polling: When client makes a request to the server it receives back a id, say requestid. 轮询:当客户端向服务器发出请求时,它会收到一个ID,即requestid。 After specified interval client polls the server with this request id to fetch a response. 指定的时间间隔后,客户端将使用此请求ID轮询服务器以获取响应。 A reasonable timeout and polling interval based on the processing time would be required. 将需要基于处理时间的合理超时和轮询间隔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM