-
2021-07-24 12:00:30
用tomcat部署了websocket项目后,测试对应的接口发现404,最后发现是servlet和tomcat版本不对应,下图是tomcat和servlet版本对应
websocket对应的连接和注解的value对应,url为ws://host:port/项目名/value
例:注解为@ServerEndpoint(value = “websocket”),host为本地,port为tomcat默认端口,uri为项目名加value,项目名为temp
url为ws://127.0.0.1:8080/temp/websocket更多相关内容 -
webSocket无法连接
2020-09-14 10:33:09 -
WebSocket无法连接问题
2021-10-21 10:48:42rosbridge连接不稳定问题 问题描述: Windows端web连接Ubuntu端rosbridge server,出现有时能连上有时连不上的问题。 最近一次发生连接不上的情况是,前一天可以连接成功,第二天,重新启动rosbridge server,从...问题描述:
最近在研究rosbridge,其原理如下图,浏览器与rosbridge server也是通过WebSocket连接的,但发现有连接不上的情况。
原因:
情况 1: 做服务器的PC IP地址变更,导致原IP连接不上。是因为做服务器的PC用了DHCP自动分配IP的方式,自动分配的IP有一定的时限,超过一定时限后变更IP。改为手动设置IP,设为固定IP地址可以解决此问题。
情况2: 有一台PC做服务器,发现无论如何都连接不上,发现是防火墙的原因,防火墙只开放了有限的端口给外部访问,通过关闭防火墙或者开发要访问的接口后,该问题得到解决。WebSocket握手阶段,client端发送http GET请求,如果服务器防火墙进行了拦截,将无法发出此请求,client端或者server端都将抓不到此http请求数据
CURL工具发送http请求
WebSocket协议
WebSocket并不是全新的协议,而是利用了HTTP协议来建立连接。我们来看看WebSocket连接是如何创建的。
首先,WebSocket连接必须由浏览器发起,因为请求协议是一个标准的HTTP请求,格式如下:
GET ws://localhost:3000/ws/chat HTTP/1.1 Host: localhost Upgrade: websocket Connection: Upgrade Origin: http://localhost:3000 Sec-WebSocket-Key: client-random-string Sec-WebSocket-Version: 13
该请求和普通的HTTP请求有几点不同:
GET请求的地址不是类似/path/,而是以ws://开头的地址;
请求头Upgrade: websocket和Connection: Upgrade表示这个连接将要被转换为WebSocket连接;
Sec-WebSocket-Key是用于标识这个连接,并非用于加密数据;
Sec-WebSocket-Version指定了WebSocket的协议版本。随后,服务器如果接受该请求,就会返回如下响应:
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: server-random-string
该响应代码101表示本次连接的HTTP协议即将被更改,更改后的协议就是Upgrade: websocket指定的WebSocket协议。
现在,一个WebSocket连接就建立成功,浏览器和服务器就可以随时主动发送消息给对方。消息有两种,一种是文本,一种是二进制数据。通常,我们可以发送JSON格式的文本,这样,在浏览器处理起来就十分容易。来源: WebSocket
wireshark抓取到的数据
WebSocket握手阶段,发出的请求与回应信息
请求:
回应:
遗留问题:
更换服务器端口后,可以建立连接,但是抓取不到请求与回应数据,暂无解 -
Python WebSocket长连接心跳与短连接的示例
2021-01-19 23:22:18ws = websocket.WebSocketApp(ws://echo.websocket.org/, on_message = on_message, on_error = on_error, on_close = on_close) ws.on_open = on_open ws.run_forever() 长连接,参数介绍: (1)url: ... -
WebSocket连接请求被Spring Security拦截, WebSocket无法连接
2021-06-16 19:40:09使用Spring Security时,Security默认会拦截WebSocket连接,尝试了在 configure(HttpSecurity httpSecurity) 中各种配置还是无效,后来经过尝试,在使用Spring Security时,Security默认会拦截WebSocket连接。
最近项目中使用Spring Security进行验证过滤,后来发现Spring Security拦截http的同时也拦截了websocket,导致websocket无法连接,尝试各种方法,包括
configure(HttpSecurity httpSecurity)
中各种配置还是无效,后来经过尝试,最终发现,在
void configure(WebSecurity webSecurity)中设置即可:
@Override public void configure(WebSecurity webSecurity){ webSecurity.ignoring().antMatchers( "/ws/**" ); }
完整代码:
@Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired UserDetailsService userDetailService; @Autowired private RestfulAccessDeniedHandler restfulAccessDeniedHandler; @Autowired private RestAuthenticationEntryPoint restAuthenticationEntryPoint; @Override protected void configure(HttpSecurity httpSecurity) throws Exception { //super.configure(http); // TODO Auto-generated method stub httpSecurity.csrf()// 由于使用的是JWT,我们这里不需要csrf .disable() // .sessionManagement()// 基于token,所以不需要session // .sessionCreationPolicy(SessionCreationPolicy.STATELESS) // .and() .authorizeRequests() .antMatchers(HttpMethod.GET, // 允许对于网站静态资源的无授权访问 "/", "/*.html", "/favicon.ico", "/**/*.html", "/**/*.css", "/**/*.js", "/***/**/*.html", "/***/**/*.css", "/***/**/*.js", "/swagger-resources/**", "/v2/api-docs/**", "/**/FAQ", "/**/pmq/public" ) .permitAll() .antMatchers("/user/login", "/task/optional_data_info")// 对登录注册要允许匿名访问 .permitAll() .antMatchers(HttpMethod.OPTIONS)//跨域请求会先进行一次options请求 .permitAll() // .antMatchers("/**")//测试时全部运行访问 // .permitAll() .anyRequest()// 除上面外的所有请求全部需要鉴权认证 .authenticated(); // 禁用缓存 httpSecurity.headers().cacheControl(); // 添加JWT filter httpSecurity.addFilterBefore(jwtAuthenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class); //添加自定义未授权和未登录结果返回 httpSecurity.exceptionHandling() .accessDeniedHandler(restfulAccessDeniedHandler) .authenticationEntryPoint(restAuthenticationEntryPoint); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { //super.configure(auth); auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder()); } //忽略websocket拦截 @Override public void configure(WebSecurity webSecurity){ webSecurity.ignoring().antMatchers( "/ws/**" ); } @Bean public UserDetailsService userDetailsService() { return new PhotovoltaicUserDetailsService(); } @Bean public PasswordEncoder passwordEncoder(){ return new BCryptPasswordEncoder(); } @Bean public JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter(){ return new JwtAuthenticationTokenFilter(); } @Bean @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } }
-
SpringBoot集成WebSocket长连接实际应用详解
2020-08-19 02:26:43主要介绍了SpringBoot集成WebSocket长连接实际应用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧 -
Websocket无法连接
2017-11-28 14:21:10Websocket无法连接 [问题点数:40分,结帖人qq542369628] 不显示删除回复 显示所有回复 显示星级回复 显示得分回复 只显示楼主 收藏 qq542369628 Waitforsniping -
springboot websocket无法连接的问题
2020-02-13 14:58:53情况说明:websocket在打成war包放到tomcat下面运行时可以连接成功,但是打成jar包放到服务器运行时就连接不上 错误提示 :Error during WebSocket handshake: Unexpected response code: 404 原因找了很久很久,... -
C# WinForm客户端连接 WebSocket
2020-07-28 09:04:52基于VS2019,使用WinForm作为WebSocket客户端,连接WebSocket服务器并进行数据通信。 -
springboot整合WebSocket长连接
2019-01-09 17:09:40针对springboot整合websocket实现长连接的实例,包含前后端内容 -
Vue通过WebSocket建立长连接的实现代码
2020-10-16 01:32:23主要介绍了Vue通过WebSocket建立长连接的实现代码,文中给出了问题及解决方案,需要的朋友可以参考下 -
Websocket无法连接问题
2019-08-06 11:20:57websocket 连接在刚开始运行正常,运行10分钟后新建连接则报告错误: ...此时查看websocket连接,会发现有256个连接已经建立,但是无法建立新的连接。 如果关闭当前的Chrome tab网页,则其他tab的网页立刻可以建立... -
websocket双向连接
2021-01-13 19:39:16页面实现实时从服务器获取到发送的数据 -
websocket无法连接到nginx代理的服务器
2018-10-18 16:04:00今天在使用websoket的时候,发现无法连接到nginx代理的服务器,最后的解决办法是在nginx的配置文件里面加上下面这个配置location /websocket: location /websocket { proxy_pass http://ip:端口; ... -
html5 websocket 建立连接通讯
2017-01-03 14:36:03html5 websocket 建立连接通讯 -
java与微信小程序实现websocket长连接
2020-08-26 00:52:26主要为大家详细介绍了java与微信小程序实现websocket长连接,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 -
Springboot多连接池+websocket
2018-12-25 10:31:18Springboot多连接池+websocket,相关详细技术说明可进入我的CSDN看博文哦~~如果有问题可在csdn上留言或者通过QQ694335719联系 -
Go 实现百万WebSocket连接的方法示例
2020-09-18 21:05:40主要介绍了Go 实现百万WebSocket连接的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧 -
SpringBoot WebSocket服务端无法连接
2021-04-21 18:16:04从代码上分析,这个websocket服务端的代码非常简单,但客户端就是死活无法连接,郁闷得不要不要的,最后排查问题往往出现在一些小的细节上。 解决 在spring security配置类中增加如下匿名访问就可以了。 ... -
websocket 心跳连接
2019-04-20 14:39:38前端实现 websocket心跳连接 支持心跳检测和心跳重连 -
WebSocket部署服务器但外网无法连接的解决方法
2020-10-19 02:49:29WebSocket是html5新增加的一种通信协议,目前流行的浏览器都支持这个协议,例如Chrome,Safari,Firefox,Opera,IE等等,下面这篇文章主要给大家介绍了关于WebSocket部署服务器但外网无法连接的解决方法,需要的朋友可以... -
WebSocket长连接
2021-12-13 16:55:32使用长连接WebSocket搭建聊天室,使用Django3的进行配置;也包含一些WebSocket原理; -
WebSocket部署到服务器出现连接失败问题的分析与解决
2020-10-19 02:33:36主要给大家介绍了关于WebSocket部署到服务器出现连接失败问题的分析与解决方法,文中给出了详细的介绍供大家参考学习,文末也给出了demo下载地址,需要的朋友们可以下载学习,下面随着小编来一起学习学习吧。 -
一个简单的网页 Websocket 连接并实现心跳 Heartbeat
2021-01-08 01:13:29创建 Socket 连接很简单,一行代码即可。 let ws = new WebSocket('wss://example.com/'); 如果服务器采用 SSL,只需要将 ws:// 替换成 wss:// let ws = new WebSocket('wss://echo.websocket.org/'); 然后是通过... -
用okhttp实现webSocket长连接
2016-08-24 15:49:41用okhttp实现webSocket长连接,可以接收服务端消息,向服务端发送消息,心跳包,维护长连接 -
Android 实现WebSocket长连接
2022-03-31 18:16:59最近项目中引入了实时刷新和接收服务器数据的功能,考量后通过WebSocket长链接来实现。 接下来了解一下webSocket 的特点: 1、建立在 TCP 协议之上,服务器端的实现比较容易。 2、与 HTTP 协议有着良好的兼容性。... -
webSocket通讯实例,长连接
2017-12-15 11:54:06android webSocket 实时通讯长连接 ,使用autobahn框架,完整代码下载 -
websocket 无法连接 onerror
2017-10-13 16:05:31@ServerEndpoint 注解是一个类层次的注解,它的功能主要是将目前的类定义成一个websocket服务器端。注解的值将被用于监听用户连接的终端访问URL地址。 onOpen 和 onClose 方法分别被@OnOpen和@OnClose 所注解... -
WebSocket建立连接的过程
2022-03-02 19:39:30二、webSocket建立连接的过程 一、WebSocket是什么? WebSocket实现了浏览器与服务器全双工通信,能更好的节省服务器资源和带宽并达到实时通讯的目的。解决了http无状态、短链接和服务器端无法主动给客户端推送数据... -
websocket 解决链接失败问题
2018-01-10 10:52:17tomcat运行在 5.0+以上版本。发包大小超出范围找到项目...-- websocket 发送内容长度设置(默认8192字节) --> <param-name>org.apache.tomcat.websocket.textBufferSize <param-value>5242800 </context-param>