This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/TM4C1292NCPDT: TCP Socket application close on NDK

Part Number: TM4C1292NCPDT

Tool/software: TI-RTOS

Hi,

I am using TI NDK - ndk_2_25_00_09 and TI RTOS - tirtos_tivac_2_16_01_14 for my DUT which is TM4C1292NCPDT. 

i have developed an application for Modbus Slave TCP protocol which is running on top of NDK stack. i have created TCP socket thread for Modbus TCP packets i.e. port number 502 and its opening TCP channel and closing TCP channel when Modbus Client application wants to connect and disconnect respectively.

find the wireshark snapshot.

No 3,4 and 5  - For connection establishment.

No. 6,7,8 and 9 - For disconnect.

Here 192.168.8.2 - Desktop i.e. Modbus TCP client application running system.

192.168.8.4 - is My DUT ( TM4C device) i.e. Modbus Slave TCP application running device.

This is working perfect when the Cient application closes and Disconnect. but when PC power is turned OFF when client application is connected, i will not be able to communicate modbus tcp transaction, whereas i will be able to establish the TCP connection and i will be able to ping properly.

here i found that Modbus TCP socket is not getting closed properly when client application is closed abruptly.

how we can handle this situation for my application? even though client application closed abruptly, my TCP socket needs to be closed after some times or after verifying something.

Regards

Bala

  • Hello Bala,

    A way to go about this would be to used the socket option SO_KEEPALIVE to know if the connection on the socket is still active. You can find more info about it on the NDK API Refrence Guide under getsockopt.

    Hope that helps,
    Gerardo
  • Hello Gerardo,

    Thank you for the information. actually i was used SO_KEEPALIVE in my application, the problem here is keep alive idle time period. it was set as 72000 by default and now i have changed to 100. Now i will be see that application socket is getting closed after 10 seconds.

    REgards

    Bala

  • Hello Gerardo,

    I am also getting the "Retrasmit timeout" error message in the console along with keep alive message. please find the snapshot.

    i am using the following NDK_setsockopt() function for my application. i believe this is something related to TCP socket settings. 

    int cmd_arg = 1; 
    ret = setsockopt( s, SOL_SOCKET, TCP_NODELAY, (char *) &cmd_arg, sizeof(cmd_arg) ); 
    
    int cmd_arg = 0;
    ret = setsockopt( s, SOL_SOCKET, SO_BLOCKING, (char *) &cmd_arg, sizeof(cmd_arg) ); 
    
    int cmd_arg = 0;
    ret = setsockopt( s, SOL_SOCKET, SO_KEEPALIVE, (char *) &cmd_arg, sizeof(cmd_arg) ); 

    I am using this settings between _bind() and _connect(). 

    do you have any suggestion for this error?

    Regards

    Bala

  • Bala,

    This message is generated by TCP when it has sent a packet of data to a network peer, and the peer has not replied in the expected amount of time. This can be just about anything; the peer has gone down, the network is busy, the network packet was dropped or corrupted, and so on.

    Best Regards,
    Gerardo

  • Hi Gerardo,

    can we increase the TCP timeout interval in NDK? if so can you please locate me where it could be?

    Reagrds
    Bala
  • Bala,

    The NDK doesn't provide a way to modify that. If you really needed to you could go into the code and modify it yourself but this is not recommended and we would not be able to offer support with any issues that may arise because of it.

    BR,
    Gerardo