multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

Files at this revision

API Documentation at this revision

Comitter:
emilmont
Date:
Thu Jul 26 15:15:33 2012 +0000
Parent:
5:2a1463aab8f2
Child:
7:dedf5dde9798
Commit message:
New UDP Socket API

Changed in this revision

EthernetInterface.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Mon Jul 23 13:48:26 2012 +0000
+++ b/EthernetInterface.lib	Thu Jul 26 15:15:33 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#cec293071eed
+http://mbed.org/users/mbed_official/code/EthernetInterface/#b7a3766f6253
--- a/main.cpp	Mon Jul 23 13:48:26 2012 +0000
+++ b/main.cpp	Thu Jul 26 15:15:33 2012 +0000
@@ -1,32 +1,28 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
-
-int main() 
-{
+ 
+int main() {
     EthernetInterface eth;
     eth.init(); //Use DHCP
-
     eth.connect();
     
     UDPSocket sock;
-    sock.bind(0); //Use a random port
+    sock.init();
     
-    char daytime_cmd[] = "plop"; //Does not matter
-    sock.sendTo(daytime_cmd, sizeof(daytime_cmd) - 1, "utcnist.colorado.edu", 37, 3000);
+    char out_buffer[] = "plop"; // Does not matter
+    UDPPacket out_packet(out_buffer, sizeof(out_buffer));
+    out_packet.set_address("utcnist.colorado.edu", 37);
+    sock.sendTo(out_packet);
     
-    char* inHost;
-    int inPort;
-    char in_buf[4];   
-    int ret = sock.receiveFrom((char*)in_buf, 4, &inHost, &inPort, 3000);
-      
-    unsigned int timeRes = ntohl( *((unsigned int*)in_buf));
-      
-    printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", ret, inHost, inPort, timeRes);
-      
-    sock.close();  
+    char in_buffer[4];
+    UDPPacket in_packet(in_buffer, sizeof(in_buffer));
+    int n = sock.receiveFrom(in_packet);
     
-    eth.disconnect();  
-
-    while(1) {
-    }
+    unsigned int timeRes = ntohl( *((unsigned int*)in_buffer));
+    printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", n, in_packet.get_address(), in_packet.get_port(), timeRes);
+    
+    sock.close();
+    
+    eth.disconnect();
+    while(1) {}
 }
--- a/mbed-rtos.lib	Mon Jul 23 13:48:26 2012 +0000
+++ b/mbed-rtos.lib	Thu Jul 26 15:15:33 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#4629f61a197e
+http://mbed.org/users/mbed_official/code/mbed-rtos/#4238c328365e