[英]What is the best practice for closing a connection from within a server endpoint?
I have a custom configurator set up that grabs the cookie and processes it. 我有一个自定义配置器,可以抓取cookie并对其进行处理。 The output is added to the user properties on the config. 输出将添加到配置的用户属性中。
In the @OnOpen
-annotated method, I compare that value with a value from the path. 在@OnOpen
-annotated方法中,我将该值与路径中的值进行比较。 If there is a mismatch, then I want to close the socket, with a 1008, Violated Policy reason. 如果不匹配,则出于1008违反政策的原因,我想关闭套接字。
What is the best way to accomplish this? 做到这一点的最佳方法是什么?
I could: 我可以:
@OnClose
method, passing the reason 手动调用@OnClose
方法,并传递原因 @OnError
be invoked 引发异常并让@OnError
被调用 I'd like the socket to be closed and Tyrus to clean up the resources. 我希望关闭插座,并希望Tyrus清理资源。 I've looked over the documentation, but didn't see an answer to how resources are cleaned up. 我查看了文档,但是没有找到有关如何清理资源的答案。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks. 谢谢。
never invoke @OnClose
manually - that won't accomplish anything. 永远@OnClose
手动调用@OnClose
不会完成任何事情。
See Session.close(CloseReason)
. 请参见Session.close(CloseReason)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.