websocket 代码在 Prod Tomcat 服务器上不起作用

编程入门 行业动态 更新时间:2024-10-23 08:27:00
本文介绍了websocket 代码在 Prod Tomcat 服务器上不起作用 - 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试运行我的第一个 websocket 应用程序并参考了 这个链接来获取一些示例代码.我只是创建了 CustomEndPointWSClient 类、 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:关键词]

本文发布于:2023-04-30 04:00:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1389337.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上不   代码   服务器   websocket   Tomcat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!