Search code examples
javatcpsmpp

Correct closing tcp connection throw java


I am writing ESME using logica smpp lib, but have a serious problem - when SMSC send to ESME [FIN, ACK], ESME do not answer correct.

Here TCP dump:

2751.016216 ESME -> SMSC         SMPP SMPP Submit_sm 
2751.019818         SMSC -> ESME SMPP SMPP Submit_sm - resp: "Throttling error (ESME exceeded allowed message limits)" 
2751.136172 ESME -> SMSC         TCP 42265 > 5001 [ACK] Seq=1651885221 Ack=3959508692 Win=123 Len=0 
2774.588453         SMSC -> ESME TCP 5001 > 42265 [FIN, ACK] Seq=3959508692 Ack=1651885221 Win=32768 Len=0 
2774.741502 ESME -> SMSC         TCP 42265 > 5001 [ACK] Seq=1651885221 Ack=3959508693 Win=123 Len=0 
2821.032427 ESME -> SMSC         SMPP SMPP Submit_sm 
2821.033502         SMSC -> ESME TCP 5001 > 42265 [RST] Seq=3959508693 Ack=0 Win=32768 Len=22 

How to solve this? Is it possible to handle this packet?


Solution

  • In class TCPIPConnection, method - public ByteBuffer receive() you should do something like this:

                        bytesRead = inputStream.read(receiveBuffer, 0, bytesToRead);
                        if (bytesRead == -1){
                            //close connection here
                        }