简体   繁体   English

如何在TCP连接上收到[FIN,ACK]时通知Java应用程序?

[英]How can a Java application be informed on receipt of a [FIN,ACK] on a TCP connection?

I have 2 connections established from a JMeter instance to an Apache Server, and from the Apache server to a Java application deployed in Jonas. 我从JMeter实例到Apache服务器,从Apache服务器到Jonas中部署的Java应用程序建立了2个连接。

When I kill the JMeter process, the connection to Apache is closed with a [RST]. 当我杀死JMeter进程时,使用[RST]关闭了到Apache的连接。 Then Apache sends a [FIN, ACK] to Jonas. 然后Apache将[FIN,ACK]发送给Jonas。 Jonas has not sent all data, so it keeps sending data. 乔纳斯(Jonas)尚未发送所有数据,因此会一直发送数据。 Jonas closes the connection later with a [FIN,ACK]. Jonas稍后用[FIN,ACK]关闭连接。 This behaviour is described in TCP RFC. TCP RFC中描述了此行为。

So, the problem is Apache receives all data from Jonas, even if Apache can not send it to JMeter. 因此,问题在于,即使Apache无法将其发送到JMeter,Apache也会从Jonas接收所有数据。

My question is: Can my Java application be triggered on receipt of the FIN,ACK send from Apache ? 我的问题是:我的Java应用程序可以在收到Apache发出的FIN,ACK时触发吗?

Not directly, eventually java may throw a IOException from the InputStream or OutputStream but this is platform dependent. 并非直接,最终java可能会从InputStream或OutputStream抛出IOException,但这取决于平台。

there was talk of a "raw sockets" java implementation prior to the release of JDK 7 but somehow I don't think it ever got off the ground. 在JDK 7发行之前,曾有过关于“原始套接字”的Java实现的讨论,但是以某种方式,我认为它从未出现过。

Can my Java application be triggered on receipt of the FIN,ACK send from Apache ? 我的Java应用程序可以在收到来自Apache的FIN,ACK时触发吗?

Yes, but you would have to be reading from the connection. 是的,但是您必须从连接中读取。 You will get end of stream in one of its various forms, depending on which read method you call. 根据调用的读取方法,您将以各种形式之一结束流。 See the Javadoc. 请参阅Javadoc。

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

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