make the mbed become the udp server to receive the data from the client.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of UDPEchoServer by
main.cpp@6:709bdd1667f3, 2014-10-30 (annotated)
- Committer:
- shiyilei
- Date:
- Thu Oct 30 16:59:33 2014 +0000
- Revision:
- 6:709bdd1667f3
- Parent:
- 2:6b1012d93eb2
make the mbed become the ; * udp server to receive the data from the; * client.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shiyilei | 6:709bdd1667f3 | 1 | /***************************************** |
shiyilei | 6:709bdd1667f3 | 2 | *file:UDP Server app |
shiyilei | 6:709bdd1667f3 | 3 | *Creator:JacobShi |
shiyilei | 6:709bdd1667f3 | 4 | *Time:2014/10/29 |
shiyilei | 6:709bdd1667f3 | 5 | * Description: make the mbed become the |
shiyilei | 6:709bdd1667f3 | 6 | * udp server to receive the data from the |
shiyilei | 6:709bdd1667f3 | 7 | * client. |
shiyilei | 6:709bdd1667f3 | 8 | ***************************************/ |
mbed_official | 0:3e54841149df | 9 | #include "mbed.h" |
emilmont | 1:3f409cd0bede | 10 | #include "EthernetInterface.h" |
shiyilei | 6:709bdd1667f3 | 11 | #define PORT 8080 |
shiyilei | 6:709bdd1667f3 | 12 | #define SIZE 100 |
shiyilei | 6:709bdd1667f3 | 13 | char data_buffer[100]; |
shiyilei | 6:709bdd1667f3 | 14 | int main(void) |
shiyilei | 6:709bdd1667f3 | 15 | { |
emilmont | 1:3f409cd0bede | 16 | EthernetInterface eth; |
emilmont | 1:3f409cd0bede | 17 | UDPSocket server; |
shiyilei | 6:709bdd1667f3 | 18 | Endpoint endpoint; |
shiyilei | 6:709bdd1667f3 | 19 | eth.init(); |
shiyilei | 6:709bdd1667f3 | 20 | eth.connect(); |
shiyilei | 6:709bdd1667f3 | 21 | printf("the ipaddr of the mbed is%s\n",eth.getIPAddress()); |
shiyilei | 6:709bdd1667f3 | 22 | server.bind(PORT); |
shiyilei | 6:709bdd1667f3 | 23 | printf("wait for the packeg\n"); |
shiyilei | 6:709bdd1667f3 | 24 | while(1) |
shiyilei | 6:709bdd1667f3 | 25 | { |
shiyilei | 6:709bdd1667f3 | 26 | |
shiyilei | 6:709bdd1667f3 | 27 | int n=server.receiveFrom(endpoint,data_buffer,SIZE); |
shiyilei | 6:709bdd1667f3 | 28 | printf("the ipaddr of the client is :%s\n",endpoint.get_address()); |
shiyilei | 6:709bdd1667f3 | 29 | data_buffer[n]='\0'; |
shiyilei | 6:709bdd1667f3 | 30 | printf("%s\n", data_buffer); |
shiyilei | 6:709bdd1667f3 | 31 | server.sendTo(endpoint,"RecvOK",sizeof("RecvOK")); |
shiyilei | 6:709bdd1667f3 | 32 | |
emilmont | 1:3f409cd0bede | 33 | } |
shiyilei | 6:709bdd1667f3 | 34 | return 0; |
shiyilei | 6:709bdd1667f3 | 35 | } |