什么时候OnWebSocketClose在Jetty 9中触发 [英] When does OnWebSocketClose fire in Jetty 9

查看:293
本文介绍了什么时候OnWebSocketClose在Jetty 9中触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的嵌入式Jetty 9 websocket服务器.在带注释的websocket实现中,我有一个这样的方法:

I have a simple embedded Jetty 9 websocket server. I have a method like this in my annotated websocket implementation:

@OnWebSocketClose
void onClose(int statusCode, String reason) {
    logger.info "Closed connection [${this}]"
    connectionManager.remove(this)
    Event closeEvent = commsEventFactory.buildCloseEvent(this, statusCode, reason)
    eventReceiver.postEvent(closeEvent)
}

我有一个spock测试,该测试使用async-http-client连接到服务器.我连接成功,可以来回发送消息.

I have a spock test which connects to the server using async-http-client. I get a successful connection and can send messages back and forth.

但是,永远不会调用onClose()(当我调用async-http-client的websocket.close()或client.close()时,甚至在测试JVM死机时也是如此).

However, onClose() is never called (when I call async-http-client's websocket.close() or client.close() or even when the test JVM dies).

我希望当插座的远端消失时,onClose会立即触发.

I expected the onClose to fire immediately when the far end of the socket disappears.

推荐答案

onClose()将触发,表明本地websocket已将状态更改为关闭".

onClose() will fire to indicate that the local side websocket has changed state to closed.

它可能是由于:

  • 远程端点已收到正确的Websocket关闭握手(也称为干净关闭")
  • 任何协议冲突(在解析或生成过程中),将尝试发出干净关闭(状态代码1002).注意:由于这种情况的性质,此关闭可能不是干净的关闭握手.
  • 连接超时,导致异常(不干净)关闭. (状态代码1006)
  • 套接字上的任何读取I/O异常,都会导致异常(不干净)关闭. (状态代码1006)
  • 套接字上的任何写入I/O异常,都会导致异常(不干净)关闭. (状态代码1006)

这篇关于什么时候OnWebSocketClose在Jetty 9中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆