@pennam
I'd like to report an apparent bug in the mbed/GIGA UDP and HttpClient classes, suggest a solution and offer the community some simple code for a DNS resolver for the GIGA.
I test my app on two different internet services and observed that on one service the UDP class 100% consistently hangs for just over 10 seconds at Udp.beginPacket. I discovered the issue relates to IPV6 in the DNS responses.
I believe the issue centers around the use of NSAPI_UNSPEC in the call to gethostbyname in SocketHelpers.cpp This says that the desired IPV4 or IPV6 response type is Unspecified. And apparently if IPV6 responses are received then the UDP class hangs for 10 seconds and then times out. Since the code is buried in the mbed classes I extracted the DNS resolution code into my sketch and updated it there.
SocketAddress _host; // Host to be used to send data, returned from gethostbyname
WiFi.getNetwork()->gethostbyname(host, &_host, NSAPI_IPv4); // NSAPI_UNSPEC, NSAPI_IPv4, NSAPI_IPv6
Udp.beginPacket(_host.get_ip_address(), 123); // NTP requests are to port 123
host contains the DNS name to be resolved eg "pool.ntp.org" or "time.google.com".
If I use the NSAPI_UNSPEC enum I consistently have the same 10 sec hang
If I use the NSAPI_IPv4 enum the whole enclosing UDP function completes in 100 ms.
So of note, the first two lines of code are an easy to use DNS resolver. They resolve a DNS name to an IPV4 address that's available as a null terminated string via a call to
_host.get_ip_address()
This should work anywhere in a GIGA after the WiFi has been connected.
EDIT: FYI The same problem occurs when using the HttpClient class too. Both of these problems are 100% repeatable on multiple GIGAs on the AT&T Fiber optic network which supports both IPV4 and IPV6.