multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

Revision:
6:25aad2d88749
Parent:
1:8e1d4987eb90
Child:
7:dedf5dde9798
--- 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) {}
 }