Socket Working Flow
87
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
Socket
calling to sl_Send (in connection-oriented mode the host application calls sl_Send instead of
sl_SendTo), the address of the remote peer is defined and datagrams from other addresses
are dropped.
–
Send Data – Send a datagram to the address that was defined during the connect process.
–
Receive Data – Receive a datagram from the address that was defined during the connect
process.
4. Close the socket. The close API returns immediately. LINGER has no meaning for connectionless
socket.
Example:
_i16 Sd;
_i16 Status;
SlSockAddrIn_t
Addr;
_i8 SendBuf[] =
"Hello World !!!"
;
_i8
RecvBuf[1460];
Sd = sl_Socket(SL_AF_INET, SL_SOCK_DGRAM, 0);
if
( 0 > Sd )
{
// error
}
Addr.sin_family
= SL_AF_INET;
Addr.sin_port
= sl_Htons(5001);
Addr.sin_addr.s_addr = SL_INADDR_ANY;
Status = sl_Bind(Sd, ( SlSockAddr_t *)&Addr,
sizeof
(SlSockAddrIn_t));
if
( Status )
{
// error
}
Addr.sin_family
= SL_AF_INET;
Addr.sin_port
= sl_Htons(5001);
Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(192,168,1,31));
Status = sl_SendTo(Sd, SendBuf, strlen(SendBuf), 0, (SlSockAddr_t*)&Addr,
sizeof
(SlSockAddr_t));
if
( strlen(SendBuf) != Status )
{
// error
}
AddrSize =
sizeof
(SlSockAddrIn_t);
Status = sl_RecvFrom(Sd, RecvBuf, 1460, 0, ( SlSockAddr_t *)&Addr, &AddrSize);
if
( 0 > Status )
{
// error
}
Status = sl_Close(Sd);
if
( Status )
{
// error
}
6.5.2.1
Multicast
IPv4 and IPv6 multicasts allow for one-to-many communication over an IP network. If a device is
interested in receiving multicasts which are sent to a specific group of devices, it may join or leave the
group by sending join or leave messages. The UDP socket that joined a group receives group multicast
packets in addition to the regular unicast packets. Television is a good example of multicasting, where
each channel is transmitted on a different multicast group. When a user changes a channel, the UDP
socket leaves the multicast group and joins another multicast group.
The SimpleLink device supports IPv4 IGMPv2 and IPv6 MLDv1 protocols for joining and leaving groups.
Users can support up to eight IPv4 multicast groups and up to eight IPv6 multicast groups. Two UDP
sockets which join the same group decrease the available multicast group only by one.