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:
shiyilei
Date:
2014-10-30
Revision:
6:709bdd1667f3
Parent:
2:6b1012d93eb2

File content as of revision 6:709bdd1667f3:

/*****************************************
*file:UDP Server app
*Creator:JacobShi
*Time:2014/10/29
* Description: make the mbed become the 
* udp server to receive the data from the
* client.
 ***************************************/
#include "mbed.h"
#include "EthernetInterface.h"
#define PORT 8080
#define SIZE 100
char data_buffer[100];
int main(void)
{
    EthernetInterface eth;
    UDPSocket server;
    Endpoint endpoint;
    eth.init();
    eth.connect();
    printf("the ipaddr of the mbed is%s\n",eth.getIPAddress());
    server.bind(PORT);
    printf("wait for the packeg\n");
    while(1)
    {
       
        int n=server.receiveFrom(endpoint,data_buffer,SIZE);
        printf("the ipaddr of the client is :%s\n",endpoint.get_address());
        data_buffer[n]='\0';
        printf("%s\n", data_buffer);
        server.sendTo(endpoint,"RecvOK",sizeof("RecvOK"));

    }
    return 0;
}