![Texas Instruments CC3220 Скачать руководство пользователя страница 85](http://html.mh-extra.com/html/texas-instruments/cc3220/cc3220_programmers-manual_1094609085.webp)
Socket Working Flow
85
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
Socket
with the client socket. The close is performed in a similar way to closing a client socket. For more
information regarding linger, see the close section of client socket.
7. Close the server socket. When there is no need to accept any new client connections, call the close
API on the server socket. The client sockets are not affected by closing the public socket, and only
new connections cannot be accepted. If the host application is required to close the clients and the
server, TI recommends closing the client socket first.
6.5.1.3
TCP Keep Alive
The keep-alive option is relevant for TCP connection only and is enabled by default. If there were no
messages between the client and the server in 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
}