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?
|
Mentor
|
![]() |
| 11Jul2012,12:04 | #2 |
|
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
like this
|
|
Go4Expert Member
|
|
| 11Jul2012,19:12 | #3 |
|
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;
}
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? |

