![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Non-blocking example of the LWIPInterface
Dependencies: LWIPInterface NetworkSocketAPI mbed-rtos mbed
Non-blocking example for the NetworkSocketAPI. Attempts to get the device's public facing IP address from ifcfg.me using the Happy Eyeballs algorithm to fetch an IPv4 or IPv6 address.
Diff: main.cpp
- Revision:
- 21:979b1db5d7da
- Parent:
- 19:03f1da306347
- Child:
- 42:d8ea089e5606
--- a/main.cpp Wed Jul 22 20:55:47 2015 +0000 +++ b/main.cpp Mon Jul 27 15:18:45 2015 +0000 @@ -31,24 +31,29 @@ char* ip; ip = wifi.getIPAddress(); if(ip!=NULL) - printf("IP Address is: %s",ip); + printf("\nIP Address is: %s\n",ip); else printf("No IP"); - SocketInterface* mySocket = wifi.allocateSocket(SOCK_UDP); + char ip_goog[20]; + wifi.getHostByName("google.com", ip_goog); + printf("Got %s\n",ip_goog); + + /* + SocketInterface* mySocket = wifi.allocateSocket(SOCK_TCP); - mySocket->setAddressPort("192.168.13.6", 7); + mySocket->setAddressPort("192.168.13.5", 7); mySocket->open(); - mySocket->send("Hello",5, 10000); - char recieved[100]; - int recv_amnt = 0; + + mySocket->send("hello",5,10000); + char recieved[6]; recieved[5] = 0; - recv_amnt = mySocket->recv(recieved, 5, 10000); + int recv_amnt = mySocket->recv(recieved, 5, 10000); printf("Recieved: %d, %s\n",recv_amnt,recieved); - mySocket->close(); + */ wifi.disconnect();