The BSD Socket Interface module is Nordic's implementation of the BSD Socket API, which is a set of standard function calls that can be used in an application. This module aims to be compatible with BSD sockets in order to simplify porting applications to use nRF5 SDK.
Currently, this SDK has the client-side implemented with the following features supported:
The BSD Socket Interface is layered on top of the transport protocols. It supports both the Nordic's IPv6 stack (UDP), as well as the LwIP stack (TCP only). Only one of them can be compiled at a time. In addition, and by default, the BSD Socket Interface automatically configures the BLE configuration options for 6LoWPAN and the entire stack is initialized upon creating the first socket. See Configuration parameters for details.
See BSD Socket interface reference for the API documentation. See the IoT examples folder for a socket TCP client example that works with the LwIP TCP Server example. The socket example is also compilable in a POSIX environment.
The BSD Socket Interface currently supports Blocking and Non-Blocking I/O. Blocking is defined as any operation that waits for resources provided by the network. Non-Blocking I/O is supported by setting O_NONBLOCK on the socket descriptor and using select. Currently, Non-Blocking I/O with select is only supported when reading data.
The following table lists the API calls and their default behavior.
API | Blocking/Non-Blocking |
---|---|
socket | Non-Blocking |
close | Non-Blocking |
connect | TCP: Blocking, UDP: Non-Blocking |
send | Blocking |
recv | Blocking |
The following is a simple socket client sending a single UDP packet.
The following is a simple socket client sending and receiving messages over TCP.
Feature | Description |
---|---|
SOCKET_TRANSPORT_ENABLE | Set to 1 to enable transport layer support. |
SOCKET_MEDIUM_ENABLE | Set to 1 to support configuration socket using medium module. |
SOCKET_AUTOINIT_ENABLE | Set to 1 to automatically configure link layer. |
SOCKET_LOGS_ENABLE | Set to 1 to enable logging to UART (must set NRF_LOG_ENABLED as well). |
SOCKET_ENABLE_API_PARAM_CHECK | Set to 1 to enable extra sanity checks. |