泽西岛SSE:关闭连接时客户端不通知

时间:2019-04-24 13:32:30

标签: java jersey server-sent-events

我使用Jersey SSE功能从服务器接收SSE。这是我的代码,几乎与我在Jersey documentation about SSE(15.6.2.1)

中找到的代码相同
Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
client.property(ClientProperties.CONNECT_TIMEOUT, CONNECTION_TIMEOUT);
WebTarget target = client.target(URL);
EventInput event = null;
int retry = 0;
while (retry <= MAX_CONNECTION_RETRY) {
    try {

        if (event == null || event.isClosed()) {
            //(re)connect
            event = createEvent(target);
        }
        InboundEvent inboundEvent = event.read();
        //reconnect if connection is closed
        if(inboundEvent==null){
            retry++;
            continue;
        }
        /// process event ...
    }
    catch(IOException ex){
        //reconnect in case this chunked input has been closed.
        retry++;
    }
}

一切正常,直到服务器过了一会儿(大约1天后)关闭连接,然后我们需要重新连接到服务器。我希望event.read()应该返回null或引发异常,但是什么也没有发生。该过程仍然停留。

该代码是否缺少任何内容。我记录了每一行,我很确定它停留在event.read()

0 个答案:

没有答案