问题描述
限时送ChatGPT账号..我正在尝试运行我的第一个 websocket 应用程序并参考了 这个链接来获取一些示例代码.我只是创建了 CustomEndPoint
、 WSClient
类、 html 文件,然后在 netbeans IDE 上运行它,它就像一个魅力.
我尝试通过将 ws://
更改为 wss://
和它适用于我的开发环境,但是当我在生产环境中部署相同的代码时,它在控制台中抛出以下错误:
WebSocket 连接到wss://xxxxxx-xxx.xxxx.com/websoc/ratesrv"失败:WebSocket 握手期间出错:意外响应代码:404
对于开发环境,我低于 WS 调用正在工作:
wsocket = new WebSocket("wss://dev_ip:8443/websoc/ratesrv");
对于我使用的 Prod(注意 url 中的 ):
wss://xxxxx-xxxxx.xx/websoc/ratesrv
我是否还需要在 PROD 中明确提供端口号?
解决方案您的 Tomcat 版本是否包含 Websockets Runtime?
如果是这样,您必须从 WAR 中删除所有 Websockets 依赖项.确保在将范围更改为提供后调用 mvn clean.
如果没有,你应该包括它.如果你想使用 Tyrus,只需输入
<块引用><依赖><groupId>org.glassfish.tyrus</groupId><artifactId>tyrus-container-servlet</artifactId><version>1.12</version></依赖><依赖><groupId>org.glassfish.tyrus</groupId><artifactId>tyrus-client</artifactId><version>1.12</version></依赖>
并在部署时检查 Tomcat 控制台中是否没有错误.
I am trying to run my first websocket app and refered this link to get some sample code . I simply created CustomEndPoint
, WSClient
class , html file and then ran it on netbeans IDE and it was working like a charm.
I tried to deploy it on tomcat server whose url is accessible using https
by changing ws://
with wss://
and it worked on my dev environment but when I deployed the same code on Production env its throwing below error in console:
WebSocket connection to 'wss://xxxxxx-xxx.xxxx.com/websoc/ratesrv' failed: Error during WebSocket handshake: Unexpected response code: 404
For dev environment I below WS call is working :
wsocket = new WebSocket("wss://dev_ip:8443/websoc/ratesrv");
For Prod I am using(note the in url):
wss://xxxxx-xxxxx.xx/websoc/ratesrv
Do I need to explicitly provide the port number as well in PROD ?
解决方案Does your Tomcat version includes Websockets Runtime?
If it does you must delete all the Websockets dependencies from your WAR. Ensure that you call mvn clean after change scope to provided.
If not, you should include it. If you want to use Tyrus just put
<dependency> <groupId>org.glassfish.tyrus</groupId> <artifactId>tyrus-container-servlet</artifactId> <version>1.12</version> </dependency> <dependency> <groupId>org.glassfish.tyrus</groupId> <artifactId>tyrus-client</artifactId> <version>1.12</version> </dependency>
And check that that there are no errors in the Tomcat console when deploy.
这篇关于websocket 代码在 Prod Tomcat 服务器上不起作用 - 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论