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.
Revision 1:8bbcb6a6ca18, committed 2019-04-02
- Comitter:
- stanly88
- Date:
- Tue Apr 02 07:12:05 2019 +0000
- Parent:
- 0:cf516d904427
- Commit message:
- K64F use static IP, broadcast UDP
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r cf516d904427 -r 8bbcb6a6ca18 main.cpp
--- a/main.cpp Mon Oct 23 21:26:36 2017 +0000
+++ b/main.cpp Tue Apr 02 07:12:05 2019 +0000
@@ -13,6 +13,13 @@
int main() {
// Bring up the ethernet interface
printf("UDP Socket example\n");
+ if( NSAPI_ERROR_OK != net.set_network("192.168.0.119",//Static IP
+ "255.255.255.0", //NetMask
+ "192.168.0.1") )// gateway )
+ {
+ printf("Static IP setting Error\n");
+ }
+
if(0 != net.connect()) {
printf("Error connecting\n");
return -1;
@@ -25,7 +32,9 @@
UDPSocket sock(&net);
SocketAddress sockAddr;
+ /*
char out_buffer[] = "time";
+
if(0 > sock.sendto("time.nist.gov", 37, out_buffer, sizeof(out_buffer))) {
printf("Error sending data\n");
return -1;
@@ -44,5 +53,22 @@
// Close the socket and bring down the network interface
sock.close();
net.disconnect();
+ */
+
+ char out_buffer[40];
+ int sendCnt = 0;
+ while(1)
+ {
+ sprintf(out_buffer,"Tx:%d\r\n", ++sendCnt);
+ if(0 > sock.sendto("192.168.0.255", 2000, out_buffer, strlen(out_buffer)))
+ {
+ printf("Error sending data\n");
+ break;
+ }
+ printf(out_buffer);
+ wait(0.5);
+ }
+ sock.close();
+ net.disconnect();
return 0;
}
\ No newline at end of file