在充当服务器的 servlet 内进行套接字编程,启动某种服务器推送环境是一个好的解决方案吗?
在充当服务器的 servlet 内进行套接字编程,启动某种服务器推送环境是一个好的解决方案吗?
Socket programming inside a servlet acting as server, is it a good solution to start a sort of server pushing environment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会在 servlet 中进行套接字编程; 如果套接字比发起它的请求寿命更长,那么您可能会遇到各种问题。
查看 cometd 项目。 Comet 是一种用于执行 HTTP 推送的技术(基本上,您保持 HTTP 连接打开任意长时间,服务器在事件发生时将其推送到客户端,而不是等待客户端轮询)。 您需要一个可以扩展以支持大量空闲连接的 Web 服务器,但这并不困难,而且 cometd 项目有许多实现可供下载。 您可以使用他们的,或者如果您想构建自己的,则可以看看它以获取灵感。
I wouldn't do socket programming from within a servlet; you're likely to have all kinds of problems if the socket outlives the Request which initiates it.
Take a look at the cometd project. Comet is a technology for doing HTTP-push (basically, you hold an HTTP connection open for an arbitrarily long time, and the server pushes events down to the client as they occur, rather than waiting for the client to poll). You need a web server which will scale to support a large number of mostly-idle connections, but that's not hard these days, and the cometd project has a number of implementations available for download. You could use theirs, or just take a look at it for inspiration if you want to build your own.