SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
The keep-alive option is relevant for TCP connections only and is enabled by default. If there were no messages between the client and the server during the time-out period, a keep-alive message is sent. This option can be disabled by calling sl_SetSockOpt with the option SL_SO_KEEPALIVE. The keep-alive time-out is also configurable using the option SL_SO_KEEPALIVETIME. The default keep-alive time-out of a new socket is 5 minutes. The value is set in seconds.
An example of disabling the keep-alive command:
_i16 Status;
SlSockKeepalive_t enableOption;
enableOption.KeepaliveEnabled = 0;
Status = sl_SetSockOpt(Sd, SL_SOL_SOCKET, SL_SO_KEEPALIVE, (_u8 *)&enableOption,sizeof(enableOption));
if( Status )
{
// error
}
An example of setting the keep-alive time-out:
_i16 Status;
_u32 TimeOut = 120;
Status = sl_SetSockOpt(Sd, SL_SOL_SOCKET, SL_SO_KEEPALIVETIME,( _u8*) &TimeOut, sizeof(TimeOut));
if( Status )
{
// error
}
Example:
_i16 Status;
SlSockAddrIn_t Addr;
_i16 ClientSd;
SlSockAddrIn_t Addr;
_i16 AddrSize = sizeof(SlSockAddrIn_t);
Addr.sin_family = SL_AF_INET;
Addr.sin_port = sl_Htons(6000);
Addr.sin_addr.s_addr = SL_INADDR_ANY;
Status = sl_Bind(Sd, ( SlSockAddr_t *)&Addr, sizeof(SlSockAddrIn_t));
if( Status )
{
// error
}
Status = sl_Listen(Sd, 1);
if( Status )
{
// error
}
ClientSd = sl_Accept( Sd, ( SlSockAddr_t *)&Addr, &AddrSize);
if(0 > ClientSd)
{
// error
}