使用java进行服务器端推送
有没有比 cometd 作为 java 长轮询框架更简单的方法? 因为我需要的是客户端指定一些参数并将它们发送到服务器。 服务器处理它们并开始连续将消息推送回客户端(看起来 就像每个服务的线程?)。客户端接收消息并显示它们。客户端有可能停止监听并实际停止服务器的服务来发送消息。也许是我太懒了 但 cometd 的例子并不像我希望的那样简短和透明。
不基于 HTML5。
is it any simpler way then cometd as long-polling framework for java?
Because what I need - is client specifies some parameters and sends them to server.
Server process them and starts contonuously pushing messages back to client (looks
like Thread-per-Service?). Client receivs messages and displays them. Client has possibility to stop listening and actually stop server's service to send messages. Maybe I'm too lazy,
but cometd's examle was not that short and transparent as I wanted it to be.
Not HTML5 based.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 SSE (服务器发送事件),您可以完全按照您所解释的方式进行操作可以,但不幸的是它是 HTML5 技术。
如果您有兴趣,可以查看 html5rocks 以获取更多信息。
With SSE ( server sent events ) you can do exactly what you explained you want to do, but unfortunately it's HTML5 technology .
If your interested you can check html5rocks for further information.
如果您懒得使用 cometd 或反向 AJAX,您可以将 Web 服务端点部署到您的客户端(最好是静态的而不是 SOAP),并让您的服务器将消息发送回您的 Web 服务(充当客户端)。
实现起来很简单。
在客户端向服务器发出的初始请求中,您还可以连同其他参数一起发送端点正在侦听通知的端口(或 URL)。
然后您只需定义通知事件并实现其余逻辑。
Well if you are too lazy for cometd or reverse AJAX you can deploy a web service endpoint to your client (preferably restful and not SOAP) and have your server send back messages to your web service (acting as a client).
It is simple to implement this.
In your clien't initial request to the server, along with the other parameter, you can also send the port (or URL) that your endpoint is listening for notification.
Then you just have to define the notification events and implement the rest of the logic.
这些人 Atmosphere 异步 WebSocket/Comet 框架 在简化服务器推送 当浏览器和/或服务器部分不支持 websockets 时,使用后备机制进行处理
These guys Atmosphere Asynchronous WebSocket/Comet Framework really made nice job at simplifying the server push process with fallbacks mechanism when browser and/or server parts does not support websockets