SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
The SimpleLink driver provides two sets of socket APIs: the SimpleLink API and a BSD-compliant API. The major differences are:
Table 7-2 describes a list of BSD socket APIs and their corresponding SimpleLink API.
BSD | SimpleLink | Server or Client | TCP or UDP | Description |
---|---|---|---|---|
socket() | sl_Socket() | Both | Both | Creates an endpoint for communication. |
bind() | sl_Bind() | Both | Both | Assigns an IP address and a port to a socket. If the socket is not bound, a port is chosen automatically. |
listen() | sl_Listen() | Server | TCP | Listens for connections on a socket. |
connect() | sl_Connect() | Client | Both | Initiates a connection on a socket. |
accept() | sl_Accept() | Server | TCP | Accepts an incoming connection on a socket. |
send(), recv() | sl_Send(), sl_Recv() | Both | Both | Writes and reads data. (On UDP, connect API which sets the default address must be called before sl_Send.) |
write(), read() | Not supported | |||
sendto(), recvfrom() | sl_SendTo(), sl_RecvFrom() | Both | UDP | Writes/reads data to/from a UDP socket. |
close() | sl_Close() | Both | Both | Causes the system to release resources allocated to a socket. In case of TCP, the connection is terminated. |
select() | sl_Select() | Both | Both | Select allows a program to monitor multiple sockets, waiting until one or more sockets become ready. |
SimpleLink supports:
| ||||
gethostbyname() | sl_NetAppDnsGet HostByName() | None | None | This is not a socket operation. It is preliminary to a socket operation, to retrieve host IP information corresponding to a host name. |
poll() | Not supported | |||
getsockopt() | sl_SockOpt() | Both | Both | Retrieves the current value of a particular socket option for the specified socket. |
setsockopt() | sl_SetSockOpt() | Both | Both | Sets a particular socket option for the specified socket. |
htons(), ntohs() | sl_Htons(), sl_Ntohs() | Both | Both | Reorders the bytes of a 16-bit unsigned value from processor order to network order. |
htonl(), ntohl() | sl_Htonl(), sl_Ntohl() | Both | Both | Reorders the bytes of a 32-bit unsigned value from processor order to network order. |
inet_ntop(), inet_pton() | - | Both | Both | Converts IP address from string representation to binary representation and vice versa. |
The following examples demonstrate the differences between these APIs:
/* Send using BSD API and checking errno value */if (send(sock, pBuff, sizeof(pBuff), 0) == -1)
{
int errsv = errno;
printf("send() failed\n");
if (errsv == ...) { ... }
}
/* Send using SimpleLink API and checking the return value */
Status = sl_Send(sock, pBuff, sizeof(pBuff), 0);
if ( Status < 0)
{
printf("send() failed\n");
if (Status == ...) { ... }
}