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: EthernetInterface NetworkAPI mbed-rtos mbed
Fork of TCP_Client_Example by
Diff: main.cpp
- Revision:
- 8:d55cac25e637
- Parent:
- 6:33b57f606f2b
- Child:
- 9:4536224842d4
--- a/main.cpp Tue Jul 17 18:32:46 2012 +0000
+++ b/main.cpp Wed Jul 18 11:24:12 2012 +0000
@@ -2,6 +2,7 @@
#include "EthernetInterface.h"
#include "NetworkAPI/ip/address.hpp"
+#include "NetworkAPI/udp/socket.hpp"
int
main()
@@ -10,10 +11,43 @@
interface.init();
interface.connect();
printf("IP Address is %s\n\r", interface.getIPAddress());
-
- network::ip::Address address;
- address.fromHostname("www.google.nl");
+
+ network::udp::Socket socket;
+ char buffer[1024];
+ int result = 0;
+
+ if (socket.open() < 0) {
+ printf("Failed to open UDP Socket\n\r");
+ return -1;
+ }
+
+ if (socket.bind(42) < 0) {
+ printf("Failed to bind UDP Socket to port 42\n\r");
+ }
- printf("Network address %s\n", address.toString().c_str());
+ while (true) {
+ result = socket.receive(buffer, 1024);
+
+ switch (result) {
+ case -1:
+ printf("Failed to read from UDP Socket\n\r");
+ return -1;
+
+ case 0:
+ printf("Nothing received...?\n\r");
+ continue;
+
+ default:
+ printf("Received %d bytes from %s:%d\n\r", result,
+ socket.getRemoteEndpoint().getAddress().toString().c_str(),
+ socket.getRemoteEndpoint().getPort());
+
+ if (!socket.getRemoteEndpoint().getAddress().isEmpty()) {
+ socket.send(buffer, result, socket.getRemoteEndpoint());
+ }
+ continue;
+ }
+ }
+
return 0;
}
\ No newline at end of file
