Java Web 服务是否可以从 Apache Tomcat 向客户端发送通知?
好吧,过去几天我试图将我的国际象棋服务器项目的计划摆上桌面。它计划由多个相互交互的 Web 服务组成。 Web服务计划用Java语言制作,并部署到带有Axis2 1.6.0 Web服务引擎的Apache Tomcat 7.0.20上。
到目前为止,将有身份验证 Web 服务、玩家池 Web 服务、验证 Web 服务和“业务逻辑”Web 服务,这将是客户端应用程序唯一知道的 Web 服务。所有客户端请求都将通过此服务完成并分别转发。
由于移动验证、历史记录等原因,所有玩家的移动都必须通过 Web 服务。当其他玩家需要知道对手已采取的行动时,就会出现问题。客户端对服务的持续请求(发现是对手下的棋子)是不可能的,因为当对手下棋时,必须立即改变玩家回合。如何使用 Java Web 服务和更早提到的技术来实现这一目标?是否可以通过网络服务联系对方玩家并通知他对手的行动?是否有其他方法可以利用这种技术范围来做到这一点?
编辑: 客户端应用程序计划为桌面应用程序,可能是 Java 或 C#。
Well, past few days I am trying to put plans for my chess server project on the table. It is planned to be made of several web services which interact mutualy. Web services are planned to be made with Java language and deployed onto Apache Tomcat 7.0.20 with Axis2 1.6.0 web service engine.
So far, there will be authentication web service, player pool web service, validation web service and 'bussiness logic' web service which will be only web service known to client application. All clients requests will be done through this service and forwarded respectively.
All players moves must go through web services because of move validation, history and so on. Problem occurs when other player needs to be informed of opponents played move. Persistant client request (to discover is opponent played move) towards service is out of question because player turn change must be immidiate when opponent play his move. How to achive this using java web services and eralier mentioned technologies? Is it possible to web service contacts opposed player and inform him about opponents move? Is there another way to do this with this scope of technologies?
Edit: Client application is planned to be desktop application, possibly Java or C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Tomcat 到 Web 浏览器推送通信的一种选项是 Comet (有时称为CometD 或 Bayeaux)。
来自维基文章:
(注意:重点是我的)
这意味着服务器可以通知客户端待处理的更改,而无需浏览器专门轮询。拥有良好的 JavaScript 框架(例如 Dojo 或 这个 jQuery 插件),您可以通过轮询无缝地与旧版浏览器配合使用。
一些了解更多有关 Comet 的好链接:
希望这会有所帮助。
One option for Tomcat-to-web-browser push communication is Comet (sometimes called CometD or Bayeaux).
From the wiki article:
(Note: Emphasis Mine)
What this means is that the server can notify the client of pending changes without the browser specifically polling. With a good JavaScript framework (such as Dojo or this jQuery plugin), you can seamlessly work with older browsers by polling.
Some good links for learning more about Comet:
Hopefully this helps.
您没有说明您的客户端技术(浏览器?桌面应用程序?)
无论如何,如果您面向家庭用户,则没有直接的解决方案。要与家庭用户合作,您需要他们打开/NAT 到其计算机所需的端口,以便您可以访问他们的 PC。对于普通家庭用户来说,这非常复杂。
对于浏览器来说,情况更加复杂,因为它们是客户端,而不是服务器。也许可以使用某些框架来模拟浏览器内的服务器(我认为至少有一个,但我不记得它的名字),但这就像通过重复 ajax 调用服务器直到做出更改一样。
最后,如果您每秒检查服务器,那么即使对于“快速国际象棋”来说,延迟也足够低。
You do not state your client technology (browser? desktop app?)
Anyway, there is no direct solution if you are addressing home users. To work with home users, you would need them to open / NAT the needed port to their computer so you can access their PC. It is very complicated to the average home user.
For browser it is even more complicated as they are clients, not servers. Maybe some framework might be used to simulate a server inside a browser (I think there is at least one but I cannot recall its name), but that would work like just by repeating ajax calls to the server until a change is made.
And last, if you are checking the server every second, that would be a latency low enough even for "fast-chess".