SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
_i16 Status,Sd,LocalSd;
_u16 nfds;
SlSockAddrIn_t LocalAddr,Addr;
SlTimeval_t timeVal;
SlFdSet_t rxSet;
LocalAddr.sin_family = SL_AF_INET;
LocalAddr.sin_port = sl_Htons(5001);
LocalAddr.sin_addr.s_addr = 0;
timeVal.tv_sec = 0;
timeVal.tv_usec = 0;
//Open TCP server socket
Sd = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
if( Status )
{
// error
}
//Bind the server socket
Status = sl_Bind(Sd, (SlSockAddr_t *)&LocalAddr, sizeof(SlSockAddrIn_t));
if( Status )
{
// error
}
//Listen
Status = sl_Listen(Sd, 0);
if( Status )
{
// error
}
nfds = Sd + 1;
SL_SOCKET_FD_ZERO( &rxSet );
SL_SOCKET_FD_SET( Sd, &rxSet );
Status = sl_Select( nfds, &rxSet, NULL, NULL, &timeVal );
if( Status )
{
// error
}
//Call select again since the trigger event has arrived (see handler example above)
SL_SOCKET_FD_ZERO( &rxSet );
SL_SOCKET_FD_SET( Sd,& rxSet );
Status = sl_Select( nfds, &rxSet, NULL, NULL, &timeVal );
int AddrSize = sizeof(SlSockAddrIn_t);
if (SL_SOCKET_FD_ISSET(Sd, &rxSet))
{
//socket is marked, call accept
LocalSD = sl_Accept(SockID, (SlSockAddr_t*)&Addr, (SlSocklen_t*) &AddrSize);
}