Set up udp communication between board (echo server) and pc (client) based on lwip example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Set up udp communication between board (echo server) and pc (client) based on lwip example

1,589 Views
mjx1126
Contributor I

Hi I'm using lwip_example for mpc5748g in s32ds for power architecture. Based on that example, I wanna build an echo server on the board, so I add the following codes in main.c and call udp_echo_init in the main function. I set up a client on pc and I checked by wireshark that it did send out the message to the ip address of mpc5748g. However, the echo server doesn't work. I think probably I miss setting up something in the main function (maybe ethernet setup and socket but I have no idea). Does anyone have experience on udp communication between such boards and pc before? Any experience would be appreciated!

By the way, is there any way that I can debug the lwip_example by printing out messages? I tried adding a uart component but it seems that it's not allowed in this particular example.

#include "lwip/udp.h"
#include "lwip/debug.h"


void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{
    if (p != NULL) {
        /* send received packet back to sender */
        udp_sendto(pcb, p, addr, port);
        /* free the pbuf */
        pbuf_free(p);
    }
}


void udp_echo_init(void)
{
    struct udp_pcb * pcb;

    /* get new pcb */
    pcb = udp_new();
    if (pcb == NULL) {
        LWIP_DEBUGF(UDP_DEBUG, ("udp_new failed!\n"));
        return;
    }

    /* bind to any IP address on port 7 */
    if (udp_bind(pcb, IP_ADDR_ANY, 7) != ERR_OK) {
        LWIP_DEBUGF(UDP_DEBUG, ("udp_bind failed!\n"));
        return;
    }

    /* set udp_echo_recv() as callback function
       for received packets */
    udp_recv(pcb, udp_echo_recv, NULL);
}

0 Kudos
0 Replies