lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] UDP send problem


From: Martin Persich
Subject: Re: [lwip-users] UDP send problem
Date: Tue, 12 Oct 2010 11:20:02 +0200

You have a quite short timeout. Isn't there a problem with ARP address resolution for tha first two times ? This may be longer then 100 ms by my mind ...
Martin Persich



----- Original Message ----- From: "Andrea Visinoni" <address@hidden>
To: "Mailing list for lwIP users" <address@hidden>
Sent: Tuesday, October 12, 2010 11:10 AM
Subject: [lwip-users] UDP send problem


Hi,
i just modified a HTTP client example to send an UDP packet to my NTP server. But it works only if i send my packet 3 times, the first 2 send are not working. With the HTTP original example it was working correctly since the first write.
Any hits? I'm using FreeRTOS + lwip 1.3.2 on a AT32UC3A board.

Andrea

portTASK_FUNCTION( vNTP, pvParameters )
{
int s, ret, err, opt;
struct sockaddr_in addr;
struct tm tm_time;
time_t timetest;
unsigned long rxbuf[12];
char            errs[255];
unsigned char msg[48] = {010, 0, 0, 0, 0, 0, 0, 0, 0}; // the packet we send

/* set up address to connect to */
memset(&addr, 0, sizeof(addr));
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = htons(123);
addr.sin_addr.s_addr = inet_addr("10.0.2.34");

/* create the socket */
if ((s = lwip_socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{
err = errno;
printk("create socket error, errno: %d\n", err);
go_idle();
}

/* connect */
if ((ret = lwip_connect(s, (struct sockaddr*)&addr, sizeof(addr))) == -1)
{
err = errno;
printk("Connect error, errno: %d\n", err);
go_idle();
}

/* set recv timeout (100 ms) */
opt = 100;
ret = lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &opt, sizeof(int));

/* Write data */
ret = lwip_write(s, (char *)msg, sizeof(msg));
ret = lwip_write(s, (char *)msg, sizeof(msg));
ret = lwip_write(s, (char *)msg, sizeof(msg));

/* Read data*/
ret = lwip_read(s, (char *)rxbuf, 12 * 4);

if (ret == 48)
{
timetest  = ntohl((time_t)rxbuf[10]);
timetest -= 2208988800U;

tm_time = gmtime(&timetest)[0];

sprintf (errs, "time : %02d/%02d/%d %02d:%02d:%02d\n", tm_time.tm_mday, tm_time.tm_mon + 1, tm_time.tm_year + 1900, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec);
printk(errs);
}

go_idle();
}

_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users





reply via email to

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