UDP Echo Server example
Dependencies: EthernetInterface mbed-rtos mbed
Diff: main.cpp
- Revision:
- 2:6b1012d93eb2
- Parent:
- 1:3f409cd0bede
- Child:
- 5:0d4087d2486d
- Child:
- 7:bd7f46b6fa23
diff -r 3f409cd0bede -r 6b1012d93eb2 main.cpp --- a/main.cpp Thu Jul 26 15:08:23 2012 +0000 +++ b/main.cpp Wed Aug 01 13:13:54 2012 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" #include "EthernetInterface.h" +#define ECHO_SERVER_PORT 7 + int main (void) { EthernetInterface eth; eth.init(); //Use DHCP @@ -8,17 +10,15 @@ printf("IP Address is %s\n", eth.getIPAddress()); UDPSocket server; - server.bind(7); + server.bind(ECHO_SERVER_PORT); + Endpoint client; char buffer[256]; while (true) { printf("\nWait for packet...\n"); - - UDPPacket packet(buffer, sizeof(buffer)); - int n = server.receiveFrom(packet); + int n = server.receiveFrom(client, buffer, sizeof(buffer)); - printf("Received packet from: %s\n", packet.get_address()); - packet.set_data(buffer, n); - server.sendTo(packet); + printf("Received packet from: %s\n", client.get_address()); + server.sendTo(client, buffer, n); } }