SCTP connection reuse

Discussion in 'C++' started by debugEnthu, Jul 10, 2012.

  1. debugEnthu

    debugEnthu New Member

    Joined:
    Jul 5, 2012
    Messages:
    11
    Likes Received:
    3
    Trophy Points:
    0
    Hi,

    I have a client-server application based on SCTP.

    When I kill the client application abnormally ( Cntrl c) and then try to reconnect to the server it gives
    "Transport endpoint is already connected" errno : EISCONN

    The code is too large to paste it here.

    I wanted to know whether SCTP connection still persists even though client application is terminated.

    Can I reuse the previous connection?
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Your server is just in the wrong state. It needs some way of detecting a killed client application and closing that connection. Once you have done that you will be able to reuse the connection.
     
    debugEnthu likes this.
  3. debugEnthu

    debugEnthu New Member

    Joined:
    Jul 5, 2012
    Messages:
    11
    Likes Received:
    3
    Trophy Points:
    0
    Code:
    bool SCTPLINKCLASS::SCTPLinkSetup ( string sourceIP, string destIP, int port_number)
    {
       //storing MMEIP address
       this->MMEIPaddress = destIP;
    
       sctpSocketFd = socket ( AF_INET, SOCK_STREAM, IPPROTO_SCTP );
     
         if( sctpSocketFd < 0 )
       {  
          cout << "sctp::ERROR : cannot open socket" << endl;
          return false;
       }
       
         /*connect with destination entity */
       ReceivedMsgIPAddr.sin_family = AF_INET;
       ReceivedMsgIPAddr.sin_addr.s_addr = inet_addr(destIP.c_str());
       ReceivedMsgIPAddr.sin_port = htons(port_number);
       int errcode = connect( sctpSocketFd,(struct sockaddr *)
                                     &ReceivedMsgIPAddr, sizeof(ReceivedMsgIPAddr ) );
       if(errcode<0)
       {  
          cout << "sctplink.cpp:: cannot connect to the server port:: " << errcode << endl;
          return false;
       }
       LinkAllocationStatus = true;
       return true;
    }
    
    this is my client code snippet for connecting to the server.

    When I abruptly terminate the client (using Cntrl C) and restart the client IMMEDIATELY
    (Please note it only happens when I restart it immediately) "connect" call above fails.
    I have checked the error code using perror it gives
    Transport endpoint is already connected.

    However, if I use the same socket (whose connect call has failed) I am able to transfer data to the server.

    I have also checked for the connected socket using /proc/net/sctp/assocs
    It shows proper socket connection.
    I have verified the client port number at server end.It shows same as listed in /proc/net/sctp/assocs.

    As per my knowledge, the connect call internally calls bind call to bind to a local port number and local IP .

    What I am confused with is that even if server doesnot handle abrupt close of client (as suggested by xptios ) but the connection is unique for (local port , local IP , remote port , remote IP)..And when I connect client second time after abruptly closing it , the port number ( ephemeral port number by OS )that is allocated during bind ( that is called from within connect system call) is different from previous one.

    So how does it show that the client is already connected?
     
    Last edited by a moderator: Jul 11, 2012

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice