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 ) );
      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 shabbir; 11Jul2012 at 19:30.. Reason: Code blocks