Java 如何使 Tomcat 8 websocket 示例工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22500384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:05:26  来源:igfitidea点击:

How to make Tomcat 8 websocket example works?

javatomcatwebsocket

提问by Bromo Programmer

I just download Tomcat 8, and I want to test WebSocket feature by testing on ECHO example application just as it is (located under ../webapps/examples/websocket folder. So I run the server and open echo.html using Mozilla.

我只是下载了 Tomcat 8,我想通过在 ECHO 示例应用程序上测试它来测试 WebSocket 功能(位于 ../webapps/examples/websocket 文件夹下。所以我运行服务器并使用 Mozilla 打开 echo.html。

I try to connect to the server from that page but it keeps throwing:

我尝试从该页面连接到服务器,但它不断抛出:

Info: WebSocket connection closed.

Can anybody tell me what am I missing? For the record, I also tried on tomcat 7.0.52 with the same result.

谁能告诉我我错过了什么?作为记录,我也在 tomcat 7.0.52 上尝试过,结果相同。

Thank you.

谢谢你。

采纳答案by john smith

The sample code as posted on:

示例代码发布在:

http://www.programmingforliving.com/2013/08/websocket-tomcat-8-ServerEndpointConfig-Configurator.html

http://www.programmingforliving.com/2013/08/websocket-tomcat-8-ServerEndpointConfig-Configurator.html

works fine with apache-tomcat-8.0.15.

与 apache-tomcat-8.0.15 一起工作正常。

回答by Richard Kuo

can not directly click from disk file, need to run from localhost:8080 http://localhost:8080/examples/websocket/echo.xhtml

不能直接从磁盘文件点击,需要从localhost:8080运行 http://localhost:8080/examples/websocket/echo.xhtml