websocket client无法连接到websocket server 的问题

1. 问题描述

生产环境的websocket client和server无法通信

2. 日志现象

通过查看日志和问题复现,定位到是client连接到server失败,导致无法通信。

出现问题的代码

出现问题的日志

21:25:27.790 [main] INFO websocket.MyWebSocketClient - start to connect... 21:25:30.943 [pool-1-thread-1] INFO websocket.MyWebSocketClient - The HTTP response from the server [200] did not permit the HTTP upgrade to WebSocket 21:26:00.823 [pool-1-thread-1] INFO websocket.MyWebSocketClient - The HTTP response from the server [200] did not permit the HTTP upgrade to WebSocket

该日志是catch异常后打印出来的。

3.分析过程

通过上面的代码我日志,知道是连接失败,但是从日志来看,以为是成功连接了,只是http和websocket的版本差异导致的,一直在分析。知直到费了大量的时间排查对比代码,才发现是服务端的SpringSecurity拦截了,导致客户端无法连接。

4. 修改方案

只需要将websocket的通信路径加入白名单即可。

相关推荐
YuMiao4 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
Jony_7 天前
高可用移动网络连接
网络协议
chilix7 天前
Linux 跨网段路由转发配置
网络协议
DianSan_ERP9 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
呉師傅9 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
gihigo19989 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
2501_946205529 天前
晶圆机器人双臂怎么选型?适配2-12寸晶圆的末端效应器有哪些?
服务器·网络·机器人
linux kernel9 天前
第七部分:高级IO
服务器·网络
数字护盾(和中)9 天前
BAS+ATT&CK:企业主动防御的黄金组合
服务器·网络·数据库
~远在太平洋~9 天前
Debian系统如何删除多余的kernel
linux·网络·debian