断开客户端会话与Spring Websocket踩踏服务器的连接 [英] Disconnect client session from Spring websocket stomp server
问题描述
我已经搜索了很多,却找不到:春季websocket踩踏服务器是否可以基于sessionId(或实际上完全基于任何东西)断开客户端的连接?
I've searched quite a bit and been unable to find this: Is there a way that a spring websocket stomp server can disconnect a client based on the sessionId (or really based on anything at all)?
在我看来,一旦客户端连接到服务器,就没有任何东西可以使服务器断开客户端的连接.
It seems to me that once a client connects to a server there is nothing that allows the server to disconnect the client.
推荐答案
据我所知,API无法满足您的需求,但是在服务器端,您只能检测到断开连接事件.如果您想断开某个客户端的连接,我认为您必须尝试使用小型解决方法,例如这个:
As far as I know the API doesn't provide what you are looking for, on server-side you can only detect disconnect events. If you want to disconnect a certain client I think you must go for a litte workaround, e.g. this one:
- 编写一个能够触发断开连接的客户端javascript函数
- 您的客户端连接到服务器后,立即在javascript中生成一个客户端ID并将其发送到服务器.记住客户端上的ID,在步骤(4)中将需要它.
- 您希望服务器断开与特定客户端的连接(由ID标识)时,将包含ID的消息发送回客户端.
- 现在,您的客户端JavaScript会评估从服务器发送的消息,并决定调用您在步骤(1)中编写的断开连接功能.
- 您的客户端断开连接.
解决方法有点麻烦,但是可以解决.
The workaround is a bit cumbersome but it'll work.
这篇关于断开客户端会话与Spring Websocket踩踏服务器的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!