gpt4 book ai didi

websocket - Tomcat7 Websocket 聊天示例 : How to load Websocket Server?

转载 作者:行者123 更新时间:2023-12-01 01:10:53 30 4
gpt4 key购买 nike

我正在尝试使用 websockets 制作自己的聊天客户端,并认为我会从 Tomcat 7 websocket chat example code. 开始。 .我已经成功编译并部署了ChatAnnotation类与 Eclipse,但是当我将 chat.html 文件重定向到我认为端点应该是什么时,什么也没有发生。

In the sample class ,他们有一个 @ServerEndpoint(value = "/websocket/chat")注释,我不确定我需要做什么(即在 web.xml 中)以使该类在服务器启动时加载并绑定(bind)该端点。

我在构造函数中放置了断点,以查看它是否在我部署时被创建,但不是。

最佳答案

这是“小魔法”:

必须有接口(interface) ServerApplicationConfig 的实现在你的类路径中:

Applications may provide an implementation of this interface to filter the discovered WebSocket endpoints that are deployed. Implementations of this class will be discovered via an ServletContainerInitializer scan.



如果您使用 Tomcat 示例,则 {CATALINA_BASE}\webapps\examples\WEB-INF\classes\websocket\ExamplesConfig.java 中存在一个类(附带编译的.class)

最后但同样重要的是:作为Tomcat 发现 事情,你不必在你的 WEB-INF/web.xml 中注册任何 servlet .该文件必须存在,但内容最少。

关于websocket - Tomcat7 Websocket 聊天示例 : How to load Websocket Server?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15589375/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com