lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] how to send udp messages circularly ?


From: address@hidden
Subject: Re: [lwip-users] how to send udp messages circularly ?
Date: Tue, 07 Jul 2009 16:21:47 +0200
User-agent: Thunderbird 2.0.0.22 (Macintosh/20090605)

So if I understood you correctly, when udp_echo_recv() sends a packet by calling udp_send(), it works, but the udp_send() in the main function does not work?

The explanation for that could be simple (and nearly described by yourself): In order to really send the packet, the MAC address needs to be known. Since it is already in the cache when a packet has been received, udp_send() called from udp_echo_recv() can send the packet directly. However, in the main function, you send to a destination that is not in the ARP cache and so the MAC address must be resolved (the packet for which you saw).

Now the question is why the ARP response is not received correctly by your device, or if it is received, why it does not lead to sending out the queued packets. Having a look at the stats (must be turned on in lwipopts.h) can tell you how many packets were sent/received by each layer and if there were errors.

BTW, did you already tell us the version of lwIP you're using? There are 'suspicious' comments that suggest old versions in your code. Also, I think I remember Altera not really shipping the latest version (if you have the latest version of theirs software, at all).

Simon



the_gadfly wrote:
The most strangely is that when  i run the udp_echo_server example ,it works
ok ! But what i need is a udp client that only sends data to PC. I have
tested it that code right now ,it works well.
Does stand-alone lwip must be used based on callback function ? Here is what i did:

---------- lwip_web_server.c--------------
nt main(void)
{
//0.6.4 struct netif *netif;
struct netif netif;
struct ip_addr ipaddr, netmask, gw;
//struct ip_addr udpDestIpAddr; //struct pbuf *p; //struct udp_pcb *pcb; //err_t err;
//char Test[]="hello world !";
unsigned int now, lasttime;
int j=0;


alt_avalon_lan91c111_if* dev_list_ptr =
(alt_avalon_lan91c111_if*)alt_ethernet_device_list.next;

printf("UDP-server using Light-weight IP (LWIP)\n\n");

/* Initialize lwip */
lwip_init();

printf ("Setting IP address to: %d.%d.%d.%d\n", IPADDR0, IPADDR1, IPADDR2,
IPADDR3);
printf ("Setting netmask to: %d.%d.%d.%d\n", NETMASK0, NETMASK1, NETMASK2,
NETMASK3);
printf ("Setting gateway address to: %d.%d.%d.%d\n\n\n", GWADDR0, GWADDR1,
GWADDR2, GWADDR3);
IP4_ADDR(&ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3);
IP4_ADDR(&netmask, NETMASK0, NETMASK1, NETMASK2, NETMASK3);
IP4_ADDR(&gw, GWADDR0, GWADDR1, GWADDR2, GWADDR3);

//0.6.4 netif = netif_add(&ipaddr, &netmask, &gw,
netif_add(&netif, &ipaddr, &netmask,
&gw,(void*)dev_list_ptr,lan91c111if_init, ip_input);
//0.6.4 netif_set_default(&netif);
netif_set_default(&netif);
//IP4_ADDR(&udpDestIpAddr, 10, 1 ,1, 52);



udp_echo_init();        // defined in httpd.c






/*
p = pbuf_alloc(PBUF_TRANSPORT,sizeof(Test),PBUF_RAM);
memcpy(p->payload, Test, sizeof(Test));


pcb = udp_new(); udp_bind(pcb, IP_ADDR_ANY, 60000); udp_connect(pcb, &udpDestIpAddr, 60000);
err=udp_send(pcb,p);
if(err==ERR_OK)
{printf("send ok !\n");}
pbuf_free(p);
udp_remove(pcb);

*/
lasttime = get_milliseconds();
while(1)
{

//0.6.4 lan91c111if_service(netif);
        lan91c111if_service(&netif);
  now = get_milliseconds();
if ((now - lasttime)*1000/alt_ticks_per_second() > ARP_TMR_INTERVAL) {
      lasttime = now;
      etharp_tmr(); // Ever 10s execute etharp_tmr()
    }


      if (++j==1000) {
        ip_reass_timer();
        j=0;
} }

}
-----------------httpd.c------------------
void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct
ip_addr *addr, u16_t port) { struct ip_addr ipaddr;
     IP4_ADDR(&ipaddr,10,1,1,52);
     if (p != NULL)
{ udp_connect(pcb,&ipaddr,60000); udp_send(pcb, p); pbuf_free(p); } }

void udp_echo_init(void) { struct udp_pcb * pcb; pcb = udp_new(); udp_bind(pcb, IP_ADDR_ANY, 60000) ; udp_recv(pcb, udp_echo_recv, NULL); }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]