cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
4,895 Views
Registered: ‎08-10-2010

Reading UDP data on the client side which is sent by UDP Server!

Hi all,

I have wrote client code for initiating a lwip UDP client using Raw API. I could connect to a UDP server and can send the data packets which I can see on the server side. Similarly I wanted to receive the datagram packets sent by the server and display it on my board using a simple printf statement. But the problem is that in this piece of code

 

"udp_recv(pcb, udpdatareceive, NULL);" 

 

I am calling the call back function 'data_recv', but for some reason it is not calling the call back function 'udpdatareceive' , in other words, it is not entering that part of the function or loop. I have tested it with a small printf function which is not responding as well. 

 

Any suggestions where I am going wrong or should I introduce some delay or some like that.

 

Here is my code:

 

 void udpdatareceive(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)

{

 int i;

static int remframesize = FRAMESIZE;

 

static int copiedframe = 0;
    while(remframesize > 1)
    {
        remframesize = remframesize - p->tot_len;
        for(i = 0; i < p->tot_len; i++)
        {
            printf("%c",*((char*) p->payload+i));
        }
        break;
    }
    if(remframesize < 1)
    {
        printf("Entire Frame Received and %d characters remaining \n", remframesize);
        remframesize = FRAMESIZE;
        copiedframe = 0;
    }
     pbuf_free(p);
}

 

This is my client init code:

void udp_client_init(void)
{
    struct udp_pcb *pcb;
    pcb = udp_new();
 
    udp_bind(pcb, IP_ADDR_ANY, UDPPORT);

    udp_recv(pcb, udpdatareceive, NULL);
}
Can anybody find out where I  am making mistake such that the call back function is not called at all, in other words it is not entering the loop.

Thanks in advance,
Raj.

 

0 Kudos
Reply
4 Replies
4,816 Views
Registered: ‎10-26-2010

Hi everyone!

I have the same problem mentioned above by  durga.rajamani .

I can send data from my board, but I can't receive any packets!

Do you have solved this issue?

 

Any suggestions?

 

Thank's in advanced

 

Rocco

 

0 Kudos
Reply
Visitor
Visitor
4,485 Views
Registered: ‎03-19-2009

I am having exact same proble on sp605 board !

 

please some one reply.

 

my code is

 

void

myudprcv(void * arg, struct udp_pcb * upcb,

                                        

struct pbuf * p,

                                        

struct ip_addr * addr,

                                        

u16_t port)

{

int x=0;

xil_printf(

"\r\n[%c]",p->len);

print("\r\nEureeeeeeeka");

}

 

 

 

int

main()

{

// Main Data Section

struct netif *netif, server_netif;

struct ip_addr ipaddr, netmask, gw;

struct ip_addr ipaddr_remote;

struct udp_pcb *pcb;

err_t err;

unsigned port = 7;

int x=0;

struct pbuf *p;

netif = &server_netif;

// Initialize Hardware Platform

init_platform();

// initliaze IP addresses to be used

IP4_ADDR(&ipaddr,  192, 168,   1, 10);

IP4_ADDR(&netmask, 255, 255, 255,  0);

IP4_ADDR(&gw,      192, 168,   1,  1);

 

IP4_ADDR(&ipaddr_remote,  192, 168,   1, 100);

 

print_app_header();

print_ip_settings(&ipaddr, &netmask, &gw);

 

lwip_init();

// Add network interface to the netif_list, and set it as default

if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) {

xil_printf(

"Error adding N/W interface\n\r");

return -1;

}

netif_set_default(netif);

// now enable interrupts

platform_enable_interrupts();

// specify that the network if is up

netif_set_up(netif);

// Creating new 'udp' based structure'pcb'

pcb = udp_new();

if (!pcb) {

xil_printf(

"Error creating PCB. Out of Memory\n\r");

return -1;

}

// bind to specified @port

err = udp_bind(pcb, IP_ADDR_ANY, port);

if (err != ERR_OK) {

xil_printf(

"Unable to bind to port %d: err = %d\n\r", port, err);

return -2;

}

 

 

// Setting up udp connection to a particular IP address

switch(udp_connect(pcb,&ipaddr_remote,7))

{

case ERR_USE:

print("Port Not Available");

return ERR_USE;

break;

case ERR_RTE:

print("No Route To destination");

return ERR_RTE;

break;

default:

break;

}

// Register receive callback for UDP

udp_recv(pcb,myudprcv,NULL);

 

xil_printf(

"UDP Successfully Started %d\n\r", port);

p = pbuf_alloc(

PBUF_TRANSPORT, 10, PBUF_POOL);

p->

payload = &mybuffer;

x=0;

// receive and process packets

while (myflag==0) {

xemacif_input(netif);

// udp_send(pcb,p);

// Delay(10);

}

// Closing all Connections

udp_disconnect(pcb);

udp_remove(pcb);

print("\r\n UDP Connection closed !");

cleanup_platform();

return 0;

}

0 Kudos
Reply
Visitor
Visitor
4,482 Views
Registered: ‎03-19-2009

when will i get "Eureeeka" on my console ??... waiting.... well if xilinx didt sovle it, my boss not gonna use spartan 6 in next deisgn.. !!
0 Kudos
Reply
Visitor
Visitor
471 Views
Registered: ‎07-17-2017

Hello,

You can look my github page below to receive and send UDP packet.

https://github.com/oguzhan-armutcu/Xilinx.git

0 Kudos
Reply