Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


FreeRTOS+UDP to create server application

Posted by Anand Jose on May 3, 2013
We are porting FreeRTOS on Pxa303 board, we want to establish ethernet communication between 2 pxa303 boards. We are using FreeRTOS+UDP(FreeRTOSV7.4.1\FreeRTOS-Plus\Source\FreeRTOS-Plus-UDP) for this purpose, twoechoclients.c(FreeRTOSV7.4.1\FreeRTOS-Plus\Demo\Common\FreeRTOS_Plus_UDP_Demos\EchoClients\) as a client applicaion, as mentioned at http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Common_Echo_Clients.shtml, website suggests desktop computer to use as a server, but we want another pxa303 board to be used as a server. Can any one guide us with how to program a server application for Pxa303 board?

RE: FreeRTOS+UDP to create server application

Posted by Richard on May 3, 2013
FreeRTOS+UDP uses a standard (ish) sockets interface, so the procedure is as per using any other Berkeley sockets IP stack:

1) Call FreeRTOS_socket() to create a socket - it will be created with a receive block time of portMAX_DELAY.
2) Call FreeRTOS_bind() to bind the socket to the echo port (port 7 by default).
3) Call FreeRTOS_recvfrom() on the socket. If configINCLUDE_vTaskSuspend is set to 1 the call will only return once data has been received.
4) Call FreeRTOS_sendto() to send the received data back from whence it came.
5) Go back to step 3 to wait for more data.

It would look something like this (I have not tried running this code! It is for example only)

static void prvEchoServer( void *pvParameters )
xSocket_t xSocket;
struct freertos_sockaddr xAddress;
/* Make sure array is large enough and that it does not overflow the
task stack. Make it static if necessary. */
int8_t cBuffer[ 25 ];
uint32_t xAddressLength = sizeof( xAddress );
long lBytes;

/* Remove compiler warning about unused parameters. */
( void ) pvParameters;

for( ;; )
/* Create a socket. */
xSocket = FreeRTOS_socket( FREERTOS_AF_INET,

/* Bind the the standard echo server port number. */
xAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
FreeRTOS_bind( xSocket, &xAddress, sizeof( xAddress ) );

/* Send a number of echo requests. */
for( ;; )
/* Wait for data to arrive on the echo port. */
lBytes = FreeRTOS_recvfrom( xSocket, cBuffer, sizeof( cBuffer ),
0, &xAddress, &xAddressLength );

/* Send the received data back from the originating address. */
FreeRTOS_sendto( xSocket, cBuffer, lBytes, 0,
&xAddress, xAddressLength );


[ Back to the top ]    [ About 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.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists