Simple UDP Server using the UIPEthernet library for ENC28J60 Ethernet boards.

Dependencies:   UIPEthernet

Revision:
3:e2462f078d64
Parent:
2:6bbdab30a1c1
Child:
4:b330511e8d56
--- a/main.cpp	Tue Sep 03 10:59:59 2019 +0000
+++ b/main.cpp	Tue Sep 03 11:19:37 2019 +0000
@@ -59,24 +59,26 @@
 
     socket.begin(PORT); // listen at port PORT for user datagrams
 
-    printf("Waiting for datagrams from UDP clients\r\n");
+    printf("Waiting for datagrams from UDP clients ...\r\n\r\n");
 
     while (1) {
         int success;
         int size = socket.parsePacket();
 
         if (size > 0) {
+            IpAddress remoteIp = socket.remoteIP();
+            char remoteAddr[16];
             do {
                 char*   data = (char*)malloc(size + 1);
                 int     len = socket.read(data, size + 1);
                 data[len] = 0;
-                printf("received: '%s", data);
+                printf("data received from %s: \r\n%s", remoteIp.toString(remoteAddr), data);
                 free(data);
             } while ((size = socket.available()) > 0);
 
             //finish reading this packet:
             socket.flush();
-            printf("'\r\n");
+            printf("\r\n");
 
             do {
                 //send new packet back to ip/port of client. This also
@@ -84,9 +86,9 @@
                 //other clients!
                 success = socket.beginPacket(socket.remoteIP(), socket.remotePort());
                 if (success)
-                    printf("beginPacket: succeeded%\r\n");
+                    printf("beginPacket: succeeded\r\n");
                 else
-                    printf("beginPacket: failed%\r\n");
+                    printf("beginPacket: failed\r\n");
 
                 //beginPacket fails if remote ethaddr is unknown. In this case an
                 //arp-request is send out first and beginPacket succeeds as soon
@@ -101,17 +103,17 @@
             success = socket.endPacket();
 
             if (success)
-                printf("endPacket: succeeded%\r\n");
+                printf("endPacket: succeeded\r\n");
             else
-                printf("endPacket: failed%\r\n");
+                printf("endPacket: failed\r\n");
 
             socket.close();
 
             //restart with new connection to receive packets from other clients
             if (socket.begin(PORT))
-                printf("restart connection: succeeded%\r\n");
+                printf("restart connection: succeeded\r\n");
             else
-                printf("restart connection: failed%\r\n");
+                printf("restart connection: failed\r\n");
         }
     }
 }