Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: WIZnetInterface WIZwiki-W7500-lecture mbed
Fork of WIZwiki-W7500-lecture2-udp by
Diff: main.cpp
- Revision:
- 3:f549134aa6c4
- Parent:
- 2:ba228e5b659c
- Child:
- 4:e802635c137f
diff -r ba228e5b659c -r f549134aa6c4 main.cpp
--- a/main.cpp Mon Feb 01 00:34:33 2016 +0000
+++ b/main.cpp Mon Feb 01 01:23:21 2016 +0000
@@ -13,26 +13,22 @@
printf("IP Address is %s\r\n", eth.getIPAddress());
UDPSocket udp_sock;
- TCPSocketConnection tcp_sock;
- tcp_sock.connect("192.168.0.244", 4545);
udp_sock.init();
udp_sock.bind(60001);
Endpoint udp_server;
udp_server.set_address("192.168.0.244",4023);
- char http_cmd[] = "GET /data/2.5/weather?q=Seoul,kr HTTP/1.0\n\n";
- tcp_sock.send_all(http_cmd, sizeof(http_cmd)-1);
- udp_sock.sendTo(udp_server,http_cmd,sizeof(http_cmd)-1);
+ char message[] = "Hello World!!\r\n";
+ udp_sock.sendTo(udp_server,message,sizeof(message)-1);
char buffer[400];
int ret;
while (true) {
- ret = tcp_sock.receive(buffer, sizeof(buffer)-1);
- if (ret <= 0) break;
- buffer[ret] = '\0';
- printf("Received %d chars from server: %s\n", ret, buffer);
+ ret = udp_sock.receiveFrom(udp_server, buffer, sizeof(buffer)-1);
+ if (ret > 0){
+ buffer[ret] = '\0';
+ printf("Received %d chars from server: %s\n", ret, buffer);
+ }
}
-
- tcp_sock.close();
+ eth.disconnect();
- eth.disconnect();
-
+ printf("Disconnected!");
}
\ No newline at end of file
