0

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 ?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Artekus
  • 3
  • 2

2 Answers2

0

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.

Damian Nikodem
  • 1,324
  • 10
  • 26
  • There is no IOException throwned from the OuputStream. Should I read the InputStream and wait for a IOException to be thrown ? or wait for -1 return ? – Artekus Mar 12 '15 at 11:08
  • if you chase through the code you should reach SocketOutputStream.socketWrite0 , This is a native method and depending on your operating system/jvm it will throw a exception ( See: http://stackoverflow.com/questions/2309561/how-to-fix-java-net-socketexception-broken-pipe ) – Damian Nikodem Mar 12 '15 at 11:25
  • The IOException will be thrown eventually but there will be a lot of buffering first, so it could take several writes to get it. – user207421 Mar 12 '15 at 11:53
0

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.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I use BufferedInputStrem. Javadoc indicates for the method read() : "If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown." After several write() in the OutpustStream, I use read() on the InputStream to check if the connection is up. But the method returns -1 even if i received ACK TCP. Probably because there is no data to read, i only want to catch FIN,ACK. Do you know another way to do this ? – Artekus Mar 12 '15 at 15:04