This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to detect that the peer closed a TCP socket

Hello,

I am using the NCS v1.5.0, the nRF9160 SoC and the modem has firmware version mfw_nrf9160_1.2.3

Based on the UDP sample, I created an application that has opens a TCP listening server then waits for a client to connect. I am using blocking sockets and poll() to wait for events on the server and client sockets. My application is here tcp_listen.zip

It all works as expected, except that my application is not informed when the remote peer has closed the its end of the client socket.

Tracing with Wireshark on the remote peer side, I can see that when it closes the socket it sends a FIN+ACK packet. To which the nRF9160 modem sends an ACK. Nothing more happens. On the application, I expected that when the remote peer closes the client socket, the call to poll() would received a POLLIN, POLLHUP or POLLERR event. But nothing happens.

How can my application be informed that the remote peer has closed its end of the client socket ? 

Best regards,

  Nelson 

  • Hello Markus,

    Any updates ? In the meanwhile, I took a look with Wireshark at the network traffic.

    On the nRF9160DK I have my TCP listening application running, and I connect to it with from my PC and send ten times a test string. To each one the module replies by upper casing the text. Then my PC application closes the socket. Again, on the module side there is no notification that the client has closed the socket.

    From the Wireshark tracing, the TCP packet sequence for when the PC closes the socket is:

    1. PC sends TCP packet with FIN and ACK
    2. Module replies with ACK
    3. PC tries to send, but apparently fails, a TCP packet with RST and ACK

    In the attached Wireshark file, my PC (the client) has IP address 192.168.178.29 and the nRF9160 module (the server) has IP address 178.50.73.204. The Wireshark tracing test_nordic.pcapng

    With the debugger, I can see that the application on the nrf9160 module is stuck in the idle task and I don't understand why. could this be related to the issues I am having ? 

  • Hello Nelson,

    NelsonGoncalves said:
    In the attached Wireshark file, my PC (the client) has IP address 192.168.178.29 and the nRF9160 module (the server) has IP address 178.50.73.204. The Wireshark tracing test_nordic.pcapng

    Thanks a lot for your input!

    NelsonGoncalves said:
    Any updates ?

    Still no news from the development team. My very apologies for that! I will try to push on this one and come back to you.

    Regards,

    Markus

  • Hello Nelson,

    Just a quick update: currently, we do not have the test setup to reproduce the issue you are facing, but our development team is looking into it as we speak. I will hopefully be able to provide you with some more updates soon.

    Regards,

    Markus

  • Hello again,

    could you update your modem firmware to version 1.3.0 and check if that makes any difference? I got the feedback from our development team that during their tests with mfw 1.3.0, poll sets event NRF_POLLHUB successfully .

    Regards,

    Markus

  • Hello Markus,

    Updating the modem firmware to version 1.3.0 fixed the issue.

    And looking at the Wireshark traces, the modem is also properly closing the TCP session tcl_close_mfw_1.3.0.pcapng

Related