• AVR Freaks

Hot!TCPIP_TCP_IsConnected returns true even after network cable is unplugged

Author
phamelin
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2015/08/26 11:29:31
  • Location: 0
  • Status: offline
2015/09/11 05:39:51 (permalink)
0

TCPIP_TCP_IsConnected returns true even after network cable is unplugged

Hello,
 
I have an application based on the tcpip_tcp_server example in Harmony. I'm not sure if the behavior I'm observing is correct or not. Once a connection is established on the socket (APP_TCPIP_SERVING_CONNECTION state in the example), the function TCPIP_TCP_IsConnected continues to return true even if I unplug the network cable. However, if I kill the client the TCPIP_TCP_IsConnected function returns false and the socket is correctly re-initialized.
 
Shouldn't the TCPIP_TCP_IsConnected function returns false when the network cable is unplugged?
 
If the tcpip_tcp_server doesn't fully handle this case, what would be the most appropriate way? I'm tempted to use TCPIP_STACK_NetIsReady but I'm not sure this is the best thing to do.
 
I'm using:
  • Ethernet PIC32 Starter Kit
  • Harmony v1.05
  • MPLAB X IDE v3.05
  • XC32 v1.40
Thank you,
 
Philippe
#1

6 Replies Related Threads

    rainad
    Moderator
    • Total Posts : 1176
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: TCPIP_TCP_IsConnected returns true even after network cable is unplugged 2015/09/11 09:31:14 (permalink)
    4.5 (2)
    It is the correct behavior.
    If you want the TCP socket to detect that there is no path to the destination host, you should enable the TCP_OPTION_KEEP_ALIVE option.
    To check that the network cable is connected use TCPIP_STACK_NetIsLinked().
     
    #2
    pwright
    Senior Member
    • Total Posts : 63
    • Reward points : 0
    • Joined: 2013/10/21 10:58:15
    • Location: Chandler, AZ
    • Status: offline
    Re: TCPIP_TCP_IsConnected returns true even after network cable is unplugged 2015/09/11 09:39:45 (permalink)
    4 (1)
    The behavior is actually correct.  Hopefully this explanation won't be too confusing, because this is a complex topic. The complexity occurs in the TCP state machine.  TCP sits on top of IP which sits on top of the Ethernet MAC which sits on top of the Ethernet Physical Layer. 
     
    The TCP layer has an industry standard statemachine.  It goes from closed -> Listen -> syn send/syn received -> established -> close wait/fin wait.  The TCPIP_TCP_isConnected function will return true if it is in the established state.
     
    With this in mind, the function will return true unless something kicks the tcp connection out of the established state.  A packet timeout for instance.  Lower layers (IP) can reset the connection.  But the IP layer won't tell the upper layer (TCP) unless it's IP address changes.
     
    With you unplugging the cable, the physical layer is down, but there is nothing to tell the IP layer that its address has changed, and it hasn't, so it doesn't signal the TCP layer that it has changed so the TCP connection state doesn't change.
     
    On older windows machines (I think 95, 98, ME) when you disconnected the Ethernet cable it would immediately kill all network connections.  On Linux and newer Windows versions it won't kill the connections right away, allowing the physical connection to be re-established.
     
    Its basically a choice between killing the connections right away, or hoping that the outage at the lower layer re-establishes and you can continue your application without having to start from scratch.
     
     
    #3
    marekb
    Starting Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2010/10/09 00:28:42
    • Location: 0
    • Status: offline
    Re: TCPIP_TCP_IsConnected returns true even after network cable is unplugged 2019/01/16 12:39:18 (permalink)
    0
    Hello,
    this is an old topic, but I have the same problem with TCPIP_TCP_IsConnected() when peer (client) close connection to pic32mz. When client close conenction, TCPIP_TCP_IsConnected() on server side (pic32mz) always return true. This behaviour is differ than in stack 5.*, why? How dedect peer disconnect with Harmony tcpip stack?
    #4
    rainad
    Moderator
    • Total Posts : 1176
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: TCPIP_TCP_IsConnected returns true even after network cable is unplugged 2019/01/17 07:04:32 (permalink)
    0
    Do you have a wireshark log you can share?
     
    #5
    marekb
    Starting Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2010/10/09 00:28:42
    • Location: 0
    • Status: offline
    Re: TCPIP_TCP_IsConnected returns true even after network cable is unplugged 2019/01/17 15:10:34 (permalink)
    0
    Ok, I figured it out.  TCPIP_TCP_CLOSE_WAIT_TIMEOUT define in harmony examples is default set to 0 (ms). If set to value greater than 0 socket closing is reported correctly (after defined timeout).
    #6
    iggardo
    Starting Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2013/07/13 07:03:47
    • Location: 0
    • Status: offline
    Re: TCPIP_TCP_IsConnected returns true even after network cable is unplugged 2019/06/13 07:27:14 (permalink)
    0
    marekb
    Ok, I figured it out.  TCPIP_TCP_CLOSE_WAIT_TIMEOUT define in harmony examples is default set to 0 (ms). If set to value greater than 0 socket closing is reported correctly (after defined timeout).



     
    Came here from google. Thank you Marekb, you made my day !
     
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5