简体   繁体   English

Jersey ChunkedOutput-如何检测客户端断开连接?

[英]Jersey ChunkedOutput - how to detect client disconnections?

Using curl as the client, jersey and grizzly on the server side, I can not get server to detect clients disconnections. 在服务器端使用curl作为客户端,球衣和灰熊,我无法让服务器检测到客户端断开连接。 Even in the case when the server write message to the client the ChunkedOutput.write succeeds. 即使在服务器向客户端写入消息的情况下,ChunkedOutput.write也会成功。

Is there a configuration either in grizzly or in jersey that can make writes to the chunked output fail? 在灰熊或球衣中是否存在可以使分块输出写入失败的配置?

Seems like when using Grizzly - Worker-thread IOStrategy the ChunkedOutput object (Jersey object) does not recognise clients disconnects immediately. 似乎使用Grizzly时-工作者线程IOStrategy的ChunkedOutput对象(Jersey对象)无法识别客户端立即断开连接。

I ended up using Same-thread IOStrategy. 我最终使用了Same-thread IOStrategy。 This might not be the best solution for all apps, but for mine it is great. 这可能不是所有应用程序的最佳解决方案,但对我而言,这很好。

NetworkListener listener = new NetworkListener("grizzly2", host, port);
listener.getTransport().setIOStrategy(SameThreadIOStrategy.getInstance());

I also tried using the Worker-thread IOStrategy and lowering the write buffer: 我还尝试使用辅助线程IOStrategy并降低写缓冲区:

NetworkListener listener = new NetworkListener("grizzly2", host, port);
listener.getTransport().setWriteBufferSize(bufferSize);

This has also worked when the bufferSize was smaller then the actual messages sent. 当bufferSize小于实际发送的消息时,这也起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM