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

539 Views Asked by At

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.

When I kill the JMeter process, the connection to Apache is closed with a [RST]. Then Apache sends a [FIN, ACK] to Jonas. Jonas has not sent all data, so it keeps sending data. Jonas closes the connection later with a [FIN,ACK]. This behaviour is described in TCP RFC.

So, the problem is Apache receives all data from Jonas, even if Apache can not send it to JMeter.

My question is: Can my Java application be triggered on receipt of the FIN,ACK send from Apache ?

2

There are 2 best solutions below

3
On BEST ANSWER

Not directly, eventually java may throw a IOException from the InputStream or OutputStream but this is platform dependent.

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.

1
On

Can my Java application be triggered on receipt of the FIN,ACK send from Apache ?

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.