For lecture UDP
Dependencies: WIZnetInterface WIZwiki-W7500-lecture mbed
Fork of WIZwiki-W7500-lecture by
Revision 3:f549134aa6c4, committed 2016-02-01
- Comitter:
- bangbh
- Date:
- Mon Feb 01 01:23:21 2016 +0000
- Parent:
- 2:ba228e5b659c
- Commit message:
- For lecture UDP
Changed in this revision
WIZwiki-W7500-lecture.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WIZwiki-W7500-lecture.lib Mon Feb 01 01:23:21 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/bangbh/code/WIZwiki-W7500-lecture/#ba228e5b659c
--- 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