make the mbed become the udp server to receive the data from the client.

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of UDPEchoServer by mbed official

main.cpp

Committer:
emilmont
Date:
2012-08-01
Revision:
2:6b1012d93eb2
Parent:
1:3f409cd0bede
Child:
6:709bdd1667f3

File content as of revision 2:6b1012d93eb2:

#include "mbed.h"
#include "EthernetInterface.h"

#define ECHO_SERVER_PORT   7

int main (void) {
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    printf("IP Address is %s\n", eth.getIPAddress());
    
    UDPSocket server;
    server.bind(ECHO_SERVER_PORT);
    
    Endpoint client;
    char buffer[256];
    while (true) {
        printf("\nWait for packet...\n");
        int n = server.receiveFrom(client, buffer, sizeof(buffer));
        
        printf("Received packet from: %s\n", client.get_address());
        server.sendTo(client, buffer, n);
    }
}