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: Fri, 3 Jul 2009 08:04:17 -0700 (PDT)

Hi:Simon ,Kieran
According Simon's reply ,i realize that  i have  made  lots of mistakes
.Though all the beginners of lwip would do that ,i still fell very sorry and
depression.
I will study what you two said a couple of days ,thank you very much !
By the way ,i made the  initialization of lwip and call httpd_init() in
another C file, may be its "multiple threads " wrong .

Best Regard
the_gadfly


Simon Goldschmidt wrote:
> 
> the_gadfly wrote:
>> [...]
>> int count=0;
>> void Delay(unsigned long ulVal)
>> {
>> while ( --ulVal != 0 );
>>   
> 
> Any good compiler will optimize this away to nothing, I guess. If you 
> really want to delay like that, you'd have to use a volatile variable.
> 
>> }
>> void
>> httpd_init(void)
>>   
> 
>  From where (which thread, what point, e.g. after stack initialization?) 
> do you call httpd_init()? This whole thing could be a threading problem: 
> a mistake that many lwIP beginners make is to use the raw API from 
> multiple threads - it may only be used from the tcpip_thread and not 
> from interrupt level!
> 
>> {
>> struct udp_pcb *pcb;
>> struct ip_addr PCipaddr;
>> struct pbuf *p,*pbuffer;
>> err_t err;
>>
>> IP4_ADDR(&PCipaddr,10,1,1,52);
>>
>> p = pbuf_alloc(PBUF_RAW,sizeof(Test),PBUF_RAM);
>> p->payload=(void *)Test;
>>   
> 
> Like Kieran already indicated: the above 2 lines are totally wrong usage 
> of the pbuf API:
> - PBUF_RAW means NO additional headers whereas you want to send a UDP 
> packet which means there will have to be UDP, IP and ARP headers added. 
> Use PBUF_TRANSPORT for sending UDP data.
> - When allocating a PBUF_RAM, you get one continous region of memory: 
> struct pbuf is at the beginning, the data buffer follows. For PBUF_RAM 
> pbufs you *must not* mess with the payload pointer! Instead, copy the 
> data from the original location into the pbuf using memcpy(p->payload, 
> src, len); if you want to do it like you did (p->payload = x), use 
> PBUF_REF instead of PBUF_RAM or lwIP might even corrupt your RAM by 
> writing to places it shouldn't.
> 
>> pbuffer = pbuf_alloc(PBUF_RAW,sizeof(Test1),PBUF_RAM);
>> pbuffer->payload=(void *)Test1;
>>
>>
>>
>> pcb = udp_new();
>> err=udp_bind(pcb, IP_ADDR_ANY,60000);
>> if(err==ERR_OK)
>> {printf("bound ok ! \n");}
>> err=udp_connect(pcb,&PCipaddr,60000);
>> if(err==ERR_OK)
>> {printf("connect ok !\n");}
>> while( count++ < 20 ) 
>> {
>>
>>
>> err=udp_send(pcb,p);
>> if(err==ERR_OK)
>> { printf("udp_send OK \n"); }
>> //Delay(1000000);
>> // Delay(1000000);
>> // Delay(1000000);
>> // err=udp_send(pcb,pbuffer);
>>
>> }
>>
>> }
> 
> This may be stupid, but did you check err == ERR_OK in all places, e.g. 
> did you see the printf's?
> If all this didn't help, it could still be that your MAC or OS port has 
> a bug...
> 
> Simon
> 
> 
> _______________________________________________
> lwip-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/lwip-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-send-udp-messages-circularly---tp24321123p24324593.html
Sent from the lwip-users mailing list archive at Nabble.com.





reply via email to

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