UDP
Sockets
are created using the
FreeRTOS_socket()
API function with the xType (second) parameter set to FREERTOS_SOCK_DGRAM and the xProtocol (third) parameter
set to FREERTOS_IPPROTO_UDP. They are configured using the
FreeRTOS_setsockopt()
function, and
bound to a port
(if necessary) using the
FreeRTOS_bind()
function.
static void prvSimpleUDPServerTask( void *pvParameters )
{
long lBytes;
struct freertos_sockaddr xBindAddress;
Socket_t xListeningSocket;
const TickType_t xSendTimeOut = 200 / portTICK_PERIOD_MS;
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET,
FREERTOS_SOCK_DGRAM,
FREERTOS_IPPROTO_UDP );
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
FreeRTOS_setsockopt( xListeningSocket,
0,
FREERTOS_SO_SNDTIMEO,
&xSendTimeOut,
sizeof( xSendTimeOut ) );
xBindAddress.sin_port = FreeRTOS_htons( 0x1234 );
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
for( ;; )
{
}
}
Creating, configuring and binding a UDP socket
<<
Back to the RTOS TCP networking tutorial index
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.