加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何使用Spring 4在我的webSocket服务器中捕获连接事件

发布时间:2020-12-15 04:42:18 所属栏目:Java 来源:网络整理
导读:我使用 spring 4,STOMP和sock.js进行了简单的Web套接字通信,遵循此 https://github.com/rstoyanchev/spring-websocket-portfolio和此 http://assets.spring.io/wp/WebSocketBlogPost.html 好吧,我想知道是否有可能捕获连接事件,例如当新客户端连接到我的服务
我使用 spring 4,STOMP和sock.js进行了简单的Web套接字通信,遵循此 https://github.com/rstoyanchev/spring-websocket-portfolio和此
http://assets.spring.io/wp/WebSocketBlogPost.html

好吧,我想知道是否有可能捕获连接事件,例如当新客户端连接到我的服务器或客户端断开连接时,是否可以在Spring 4.0.0中进行?

解决方法

这可以通过连接握手拦截器( HttpSessionHandshakeInterceptor)完成,引用 documentation:

The easiest way to customize the initial HTTP WebSocket handshake request is through a HandshakeInterceptor,which exposes “before” and “after” the handshake methods.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读