The
FreeRTOS_sendto()
TCP/IP stack API function is used to send data to a
UDP socket.
Data can only be sent after the
socket has been
created, configured, and
optionally bound to a local
port number.
As detailed on the FreeRTOS_sendto() API reference page, FreeRTOS_sendto()
can be used with standard calling semantics, or zero copy calling semantics.
This page demonstrates the standard calling semantics.
The source code below shows a RTOS task that creates a UDP socket before entering
a loop that sends a string to the socket (using the standard calling
semantics) every 1 second (1000ms). The comments in the source code
example provide more information.
static void vUDPSendUsingStandardInterface( void *pvParameters )
{
Socket_t xSocket;
struct freertos_sockaddr xDestinationAddress;
uint8_t cString[ 50 ];
uint32_t ulCount = 0UL;
const TickType_t x1000ms = 1000UL / portTICK_PERIOD_MS;
memset( &xDestinationAddress, 0, sizeof(xDestinationAddress) );
xDestinationAddress.sin_address.ulIP_IPv4 = FreeRTOS_inet_addr( "192.168.0.50" );
xDestinationAddress.sin_family = FREERTOS_AF_INET4;
xDestinationAddress.sin_port = FreeRTOS_htons( 10000 );
xSocket = FreeRTOS_socket( FREERTOS_AF_INET4,
FREERTOS_SOCK_DGRAM,
FREERTOS_IPPROTO_UDP );
configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
for( ;; )
{
sprintf( cString,
"Standard send message number %lurn",
ulCount );
FreeRTOS_sendto( xSocket,
cString,
strlen( cString ),
0,
&xDestinationAddress,
sizeof( xDestinationAddress ) );
ulCount++;
vTaskDelay( x1000ms );
}
}
Example using FreeRTOS_sendto() with the standard (as opposed to zero copy) calling semantics
<<
Back to the RTOS TCP networking tutorial index
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.