multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
Diff: main.cpp
- Revision:
- 11:d0a105f6743f
- Parent:
- 7:dedf5dde9798
- Child:
- 12:91affff3be75
--- a/main.cpp Wed May 14 15:32:24 2014 +0000 +++ b/main.cpp Tue Nov 10 02:32:49 2020 +0000 @@ -1,28 +1,21 @@ #include "mbed.h" #include "EthernetInterface.h" +#include "network.h" int main() { - EthernetInterface eth; - eth.init(); //Use DHCP - eth.connect(); - - UDPSocket sock; - sock.init(); + EthernetInterface eth; + UDPSocket sock; + Endpoint nist; - Endpoint nist; - nist.set_address("utcnist.colorado.edu", 37); + initEthernet(ð, &sock, &nist); - char out_buffer[] = "plop"; // Does not matter - sock.sendTo(nist, out_buffer, sizeof(out_buffer)); - + char out_buffer[] = "{\"type\": \"connected\", \"body\": \"hey deniz\"}"; + sock.sendTo(nist, out_buffer, sizeof(out_buffer) - 1); + char in_buffer[4]; int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer)); - - 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, nist.get_address(), nist.get_port(), timeRes); - - sock.close(); - - eth.disconnect(); + + cleanupEthernet(ð, &sock); + while(1) {} }