Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   SCTP connection reuse (http://www.go4expert.com/forums/sctp-connection-reuse-t28704/)

debugEnthu 10Jul2012 19:00

SCTP connection reuse
 
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?

xpi0t0s 11Jul2012 12:04

Re: SCTP connection reuse
 
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 11Jul2012 19:12

Re: SCTP connection reuse
 
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?


All times are GMT +5.5. The time now is 23:13.