[ ]
 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Homepage FreeRTOS Labs FreeRTOS+TCP FreeRTOS+FAT Contact / Enquiries

FreeRTOS+TCP is still in the lab
FreeRTOS+TCP is already used in commercial products and we encourage you to try it yourself. Be aware however that we are still refining its design, and the source code and documentation do not yet meet Real Time Engineers Ltd's strict quality standards.
Please use the forum for support, feedback and ideas, or contact us directly if you have a specific business interest.

Create, Configure and Bind a UDP Socket
Part of the FreeRTOS+TCP Networking Tutorial

UDP Sockets are created using the FreeRTOS_socket() API function with the xType (second) parameter set to FREERTOS_SOCK_DGRAM, 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;

   /* Attempt to open the UDP socket. */
   xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET,
                                       FREERTOS_SOCK_DGRAM,/*FREERTOS_SOCK_DGRAM for UDP.*/
                                       FREERTOS_IPPROTO_UDP );

   /* Check for errors. */
   configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );

   /* Ensure calls to FreeRTOS_sendto() timeout if a network buffer cannot be
   obtained within 200ms. */
   FreeRTOS_setsockopt( xListeningSocket,
                        sizeof( xSendTimeOut ) );

   /* Bind the socket to port 0x1234. */
   xBindAddress.sin_port = FreeRTOS_htons( 0x1234 );
   FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );

   for( ;; )
        * The socket can now send and receive data here.
Creating, configuring and binding a UDP socket

<< Back to the RTOS TCP networking tutorial index

[ Back to the top ]    [ About FreeRTOS ]    [ FreeRTOS Labs Sitemap ]    [ Main FreeRTOS Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.