IOT Sockets#

This section provides a reference to IoT Socket API functions.

The IOT socket implementation aims to emulate the standards library to the extent possible for embedded offerings from Silabs. There are substantial limitation/exceptions however, and those are mentioned in the subsequent documentation of IOT sockets.

Modules#

Address Family

Socket Type

Socket Protocol

Socket Option Id

Socket Return Codes

Functions#

int32_t
iotSocketCreate(int32_t af, int32_t type, int32_t protocol)

Create a communication socket.

int32_t
iotSocketBind(int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port)

Assign a local address to a socket.

int32_t
iotSocketListen(int32_t socket, int32_t backlog)

Listen for socket connections.

int32_t
iotSocketAccept(int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)

Accept a new connection on a socket.

int32_t
iotSocketConnect(int32_t socket, const uint8_t *ip, uint32_t ip_len, uint16_t port)

Connect a socket to a remote host.

int32_t
iotSocketRecv(int32_t socket, void *buf, uint32_t len)

Receives data from the socket.

int32_t
iotSocketRecvFrom(int32_t socket, void *buf, uint32_t len, uint8_t *ip, uint32_t *ip_len, uint16_t *port)

Receives data from the socket.

int32_t
iotSocketSend(int32_t socket, const void *buf, uint32_t len)

Send data or check if data can be sent on a connected socket.

int32_t
iotSocketSendTo(int32_t socket, const void *buf, uint32_t len, const uint8_t *ip, uint32_t ip_len, uint16_t port)

Send data or check if data can be sent on a socket.

int32_t
iotSocketGetSockName(int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)

Retrieve local IP address and port of a socket.

int32_t
iotSocketGetPeerName(int32_t socket, uint8_t *ip, uint32_t *ip_len, uint16_t *port)

Retrieve remote IP address and port of a socket.

int32_t
iotSocketGetOpt(int32_t socket, int32_t opt_id, void *opt_val, uint32_t *opt_len)

Get socket option.

int32_t
iotSocketSetOpt(int32_t socket, int32_t opt_id, const void *opt_val, uint32_t opt_len)

Set socket option.

int32_t
iotSocketClose(int32_t socket)

Close and release a socket.

int32_t
iotSocketGetHostByName(const char *name, int32_t af, uint8_t *ip, uint32_t *ip_len)

Retrieve host IP address from host name.

Function Documentation#

iotSocketCreate#

int32_t iotSocketCreate (int32_t af, int32_t type, int32_t protocol)

Create a communication socket.

Parameters
[in]af

Address family. One of the values from Address Family.

[in]type

Socket type. One of the values from Socket Type.

[in]protocol

Socket protocol. One of the values from Socket Protocol.

Returns


Definition at line 134 of file third_party/iot_socket/include/iot_socket.h

iotSocketBind#

int32_t iotSocketBind (int32_t socket, const uint8_t * ip, uint32_t ip_len, uint16_t port)

Assign a local address to a socket.

Parameters
[in]socket

Socket identification number.

[in]ip

Pointer to local IP address.

[in]ip_len

Length of 'ip' address in bytes.

[in]port

Local port number.

Returns


Definition at line 150 of file third_party/iot_socket/include/iot_socket.h

iotSocketListen#

int32_t iotSocketListen (int32_t socket, int32_t backlog)

Listen for socket connections.

Parameters
[in]socket

Socket identification number.

[in]backlog

Maximum number of the clients supported.

Returns


Definition at line 165 of file third_party/iot_socket/include/iot_socket.h

iotSocketAccept#

int32_t iotSocketAccept (int32_t socket, uint8_t * ip, uint32_t * ip_len, uint16_t * port)

Accept a new connection on a socket.

Parameters
[in]socket

Socket identification number.

[out]ip

Pointer to buffer where address of connecting socket shall be returned (NULL for none).

[inout]ip_len

pointer to length of 'ip' (or NULL if 'ip' is NULL):

  • Length of supplied 'ip' on input.

  • Length of stored 'ip' on output.

[out]port

Pointer to buffer where port of connecting socket shall be returned (NULL for none).

Returns


Definition at line 186 of file third_party/iot_socket/include/iot_socket.h

iotSocketConnect#

int32_t iotSocketConnect (int32_t socket, const uint8_t * ip, uint32_t ip_len, uint16_t port)

Connect a socket to a remote host.

Parameters
[in]socket

Socket identification number.

[in]ip

Pointer to remote IP address.

[in]ip_len

Length of 'ip' address in bytes.

[in]port

Remote port number.

Returns


Definition at line 208 of file third_party/iot_socket/include/iot_socket.h

iotSocketRecv#

int32_t iotSocketRecv (int32_t socket, void * buf, uint32_t len)

Receives data from the socket.

Parameters
[in]socket

Socket identification number.

[out]buf

Pointer to buffer where data should be stored.

[in]len

Length of buffer (in bytes).

Returns


Definition at line 227 of file third_party/iot_socket/include/iot_socket.h

iotSocketRecvFrom#

int32_t iotSocketRecvFrom (int32_t socket, void * buf, uint32_t len, uint8_t * ip, uint32_t * ip_len, uint16_t * port)

Receives data from the socket.

Parameters
[in]socket

Socket identification number.

[out]buf

Pointer to buffer where data should be stored.

[in]len

Length of buffer (in bytes).

[out]ip

Pointer to buffer where remote source address shall be returned (NULL for none).

[inout]ip_len

Pointer to length of 'ip' (or NULL if 'ip' is NULL):

  • Length of supplied 'ip' on input.

  • Length of stored 'ip' on output.

[out]port

Pointer to buffer where remote source port shall be returned (NULL for none).

Returns


Definition at line 251 of file third_party/iot_socket/include/iot_socket.h

iotSocketSend#

int32_t iotSocketSend (int32_t socket, const void * buf, uint32_t len)

Send data or check if data can be sent on a connected socket.

Parameters
[in]socket

Socket identification number.

[in]buf

Pointer to buffer containing data to send.

[in]len

Length of data (in bytes).

Returns

Note

  • The function doesn't guarantees the packets are transmitted to remote note, which are enqueued in the queue.

  • The function can only send max of 1460 bytes in case of plain TCP and UDP. For TLS, the max buffer length is 1370.


Definition at line 272 of file third_party/iot_socket/include/iot_socket.h

iotSocketSendTo#

int32_t iotSocketSendTo (int32_t socket, const void * buf, uint32_t len, const uint8_t * ip, uint32_t ip_len, uint16_t port)

Send data or check if data can be sent on a socket.

Parameters
[in]socket

Socket identification number.

[in]buf

Pointer to buffer containing data to send.

[in]len

Length of data (in bytes).

[in]ip

Pointer to remote destination IP address.

[in]ip_len

Length of 'ip' address in bytes.

[in]port

Remote destination port number.

Returns

Note

  • If number of bytes to be send exceeds the MSS size specified by remote node, the API will return IOT_SOCKET_ERROR. To know the MSS size for the socket, use sl_si91x_get_socket_mss() utility, In the case of TCP, this should be called after iotSocketConnect().

  • The function doesn't guarantees the packets are transmitted to remote note, which are enqueued in the queue.

  • The function can only send max of 1460 bytes in case of plain TCP or UDP. For TLS, the max buffer length is 1370.


Definition at line 298 of file third_party/iot_socket/include/iot_socket.h

iotSocketGetSockName#

int32_t iotSocketGetSockName (int32_t socket, uint8_t * ip, uint32_t * ip_len, uint16_t * port)

Retrieve local IP address and port of a socket.

Parameters
[in]socket

Socket identification number.

[out]ip

Pointer to buffer where local address shall be returned (NULL for none).

[inout]ip_len

Pointer to length of 'ip' (or NULL if 'ip' is NULL):

  • Length of supplied 'ip' on input.

  • Length of stored 'ip' on output.

[out]port

Pointer to buffer where local port shall be returned (NULL for none).

Returns


Definition at line 315 of file third_party/iot_socket/include/iot_socket.h

iotSocketGetPeerName#

int32_t iotSocketGetPeerName (int32_t socket, uint8_t * ip, uint32_t * ip_len, uint16_t * port)

Retrieve remote IP address and port of a socket.

Parameters
[in]socket

Socket identification number.

[out]ip

Pointer to buffer where remote address shall be returned (NULL for none).

[inout]ip_len

Pointer to length of 'ip' (or NULL if 'ip' is NULL):

  • Length of supplied 'ip' on input.

  • Length of stored 'ip' on output.

[out]port

Pointer to buffer where remote port shall be returned (NULL for none).

Returns


Definition at line 333 of file third_party/iot_socket/include/iot_socket.h

iotSocketGetOpt#

int32_t iotSocketGetOpt (int32_t socket, int32_t opt_id, void * opt_val, uint32_t * opt_len)

Get socket option.

Parameters
[in]socket

Socket identification number.

[in]opt_id

Option identifier. One of the values from Socket Option Id

[out]opt_val

Pointer to the buffer that will receive the option value.

[inout]opt_len

Pointer to length of the option value:

  • Length of buffer on input.

  • Length of data on output.

Returns

Note


Definition at line 358 of file third_party/iot_socket/include/iot_socket.h

iotSocketSetOpt#

int32_t iotSocketSetOpt (int32_t socket, int32_t opt_id, const void * opt_val, uint32_t opt_len)

Set socket option.

Parameters
[in]socket

Socket identification number.

[in]opt_id

Option identifier. One of the values from Socket Option Id.

[in]opt_val

Pointer to the option value.

[in]opt_len

Length of the option value in bytes.

Returns

Note


Definition at line 381 of file third_party/iot_socket/include/iot_socket.h

iotSocketClose#

int32_t iotSocketClose (int32_t socket)

Close and release a socket.

Parameters
[in]socket

Socket identification number.

Returns

Note

  • Calling close on server or first client socket would end up closing other socket as well.


Definition at line 395 of file third_party/iot_socket/include/iot_socket.h

iotSocketGetHostByName#

int32_t iotSocketGetHostByName (const char * name, int32_t af, uint8_t * ip, uint32_t * ip_len)

Retrieve host IP address from host name.

Parameters
[in]name

Host name.

[in]af

Address family. One of value from IOT_SOCKET_ADDRESS_FAMILY

[out]ip

Pointer to buffer where resolved IP address shall be returned.

[inout]ip_len

Pointer to length of 'ip':

  • length of supplied 'ip' on input.

  • length of stored 'ip' on output.

Returns


Definition at line 414 of file third_party/iot_socket/include/iot_socket.h