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的通信路径加入白名单即可。

相关推荐
友友马17 分钟前
『 Linux 』HTTP(一)
linux·运维·服务器·网络·c++·tcp/ip·http
2401_8725149723 分钟前
深入探究HTTP网络协议栈:互联网通信的基石
网络·网络协议·http
chenjingming6661 小时前
windows使用tcpdump.exe工具进行抓包教程
网络·测试工具·tcpdump
初黑子zzz1 小时前
rsync
网络
superconvert2 小时前
主流流媒体的综合性能大 PK ( smart_rtmpd, srs, zlm, nginx rtmp )
websocket·ffmpeg·webrtc·hevc·rtmp·h264·hls·dash·rtsp·srt·flv
蜗牛学苑_武汉2 小时前
设计模式之代理模式
java·网络·java-ee·代理模式
不良人天码星2 小时前
HTTP 协议的基本格式
网络·网络协议·http
码哝小鱼3 小时前
iptables限制网速
linux·服务器·网络
月临水3 小时前
JavaEE:网络编程(UDP)
java·网络·udp·java-ee
Coremail邮件安全4 小时前
武汉大学:如何做好高校电子邮件账号安全防护
网络·安全·邮件安全·双因素认证·敏感信息