CC3200客户端为什么反复断开、连接后无法再连接?
CC3200客户端为什么反复断开、连接后无法再连接?
我用CC3200模块做TCP SERVER时,只有一个TCP客户端反复断开、连接,大概4次以后无法再连接。分析是达到socket连接限制(因为还有其他套接字),但客户端正常断开后 sl_Recv返回0,我在返回0后有关闭套接字,为什么还会出现这种情况呢,请问是什么问题?
while(1)
{
// waiting for an app incoming TCP connection
if ( g_iSockID_App < 0 )
{
// accepts a connection form a TCP client, if there is any
// otherwise returns SL_EAGAIN
g_iSockID_App = sl_Accept(g_iSockID_AppServer, ( struct SlSockAddr_t *)&sAddr, (SlSocklen_t*)&iAddrSize);
if (g_iSockID_App == SL_EAGAIN)
{
//sl_Close(g_iSockID_App);
}
else if(g_iSockID_App < 0)
{
// error
sl_Close(g_iSockID_App);
}
else
{
// setting socket option to make the socket as non blocking
enableOption.NonblockingEnabled = 1; //0 = disabled;1 = enabled;default = 1
lRetVal = sl_SetSockOpt(g_iSockID_App,SL_SOL_SOCKET,SL_SO_NONBLOCKING, (_u8 *)&enableOption,sizeof(enableOption));
//enable/disable nonblocking mode
if( lRetVal < 0 )
{
sl_Close(g_iSockID_App);
}
}
}
else
{
// waits for 1 packets from the connected TCP client
lRetVal = sl_Recv(g_iSockID_App, g_cAppTcpBuf, TCP_CMD_RD_BUF_SIZE, 0);
if (lRetVal == SL_EAGAIN);
else if(lRetVal <=0)
{
// error
sl_Close(g_iSockID_App);
g_iSockID_App=SL_EAGAIN;
//如果客户端正常断开的返回值为0
UART_PRINT("App client failed,lRetVal=%d\n\r",lRetVal);
}
else
{
//run command
}
}
}
查一下当client端关闭socket, 再连接的时候,你的sl_Accept返回的socket no是不是在递增?
你客户端关闭的时候是怎样关闭的呢?