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: the_gadfly
Subject: Re: [lwip-users] how to send udp messages circularly ?
Date: Tue, 7 Jul 2009 06:45:13 -0700 (PDT)

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); 
} 
-- 
View this message in context: 
http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24373631.html
Sent from the lwip-users mailing list archive at Nabble.com.





reply via email to

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