# FreeRTOS+UDP to create server application

**URL:** <https://forums.freertos.org/t/freertos-udp-to-create-server-application/4915>\
**Category:** Kernel\
**Created:** [May 3, 2013, 9:09am UTC](https://forums.freertos.org/t/freertos-udp-to-create-server-application/4915 "2013-05-03T09:09:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 3, 2013, 9:09am UTC](https://forums.freertos.org/t/freertos-udp-to-create-server-application/4915/1 "2013-05-03T09:09:59Z")

</div>

**[anandjose](https://sourceforge.net/u/anandjose/)** wrote on [Friday, May 03, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/d9e408df/#efb5):

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,](http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Common_Echo_Clients.shtml%2C) 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?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [May 3, 2013, 6:42pm UTC](https://forums.freertos.org/t/freertos-udp-to-create-server-application/4915/2 "2013-05-03T18:42:16Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, May 03, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/d9e408df/#3935):

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.&nbsp; 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!&nbsp; 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,
                                FREERTOS_SOCK_DGRAM,
                                FREERTOS_IPPROTO_UDP );
    /* 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 );
    }
  }
}

```

Regards.
