[FreeRTOS Embedded IP Stack API]

xSocket_t FreeRTOS_socket( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol );

Create a UDP socket.

The function parameters are not used other than to check they contain the expected values (and only then when configASSERT() is defined in FreeRTOSConfig.h). The parameters are included in the function prototype to ensure consistency with the expected standard Berkeley sockets prototype, and for future compatibility as FreeRTOS+UDP evolves.


xDomain   Must be set to FREERTOS_AF_INET.

xType   Must be set to FREERTOS_SOCK_DGRAM.

xProtocol   Must be set to FREERTOS_IPPROTO_UDP.


If a socket is created successfully, then the socket handle is returned. If there is insufficient FreeRTOS heap memory available for the socket to be created then FREERTOS_INVALID_SOCKET is returned.

Example usage:

/* FreeRTOS+UDP sockets include */
#include “FreeRTOS_sockets.h”

void aFunction( void )
/* Variable to hold the created socket. */
xSocket_t xSocket;
struct freertos_sockaddr xBindAddress;

/* Create the socket. */

/* Check the socket was created successfully. */
/* The socket was created successfully and can now be used to send data
using the FreeRTOS_sendto() API function. Sending to a socket that has
not first been bound will result in the socket being automatically bound
to a port number. Use FreeRTOS_bind() to bind the socket to a
specific port number. This example binds the socket to port 9999. The
port number is specified in network byte order, so FreeRTOS_htons() is
used. */

xBindAddress.sin_port = FreeRTOS_htons( 9999 );
if( FreeRTOS_bind( xSocket, &xBindAddress, sizeof( &xBindAddress ) ) == 0 )
/* The bind was successful. */
/* There was insufficient FreeRTOS heap memory available for the socket
to be created. */


Example use of the FreeRTOS_socket() API function
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo & Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

New Updates to MIT licensed IoT MQTT and POSIX libraries are now available. New library IoT HTTPS is available.  Includes demo projects.

View a recording of the “OTA Update Security and Reliability” webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners
ARM Connected RTOS partner for all ARM microcontroller cores
Espressif ESP32
IAR Partner
Microchip Premier RTOS Partner
STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0
Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers
OpenRTOS and SafeRTOS
Xilinx Microblaze and Zynq partner