UDP Seerver LCinet
Dependencies: SDFileSystem WIZnetInterface mbed
Fork of UDPEchoServer by
Revision 8:47e9d7df0582, committed 2015-08-21
- Comitter:
- eunkyoungkim
- Date:
- Fri Aug 21 03:34:25 2015 +0000
- Parent:
- 7:345b078c448a
- Commit message:
- UDP Client...; - Add sock.bind
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 345b078c448a -r 47e9d7df0582 main.cpp --- a/main.cpp Fri Aug 21 02:25:23 2015 +0000 +++ b/main.cpp Fri Aug 21 03:34:25 2015 +0000 @@ -19,13 +19,12 @@ #define GATEWAY "192.168.99.1" #endif const char* ECHO_SERVER_ADDRESS = "192.168.99.100"; -const int ECHO_SERVER_PORT = 7; - +const int ECHO_SERVER_PORT = 3000; +const int ECHO_CLIENT_PORT = 2000; int main (void) { EthernetInterface eth; Serial (USBTX, USBRX); - printf("g\n"); eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway printf("Connecting\n"); eth.connect(); @@ -57,19 +56,20 @@ UDPSocket sock; sock.init(); - + sock.bind(ECHO_CLIENT_PORT); Endpoint echo_server; echo_server.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); char out_buffer[] = "Hello World"; printf("Sending message '%s' to server (%s)\n",out_buffer,ECHO_SERVER_ADDRESS); + printf("ip= %s,port=%d\r\n",echo_server.get_address(),echo_server.get_port()); sock.sendTo(echo_server, out_buffer, sizeof(out_buffer)); char in_buffer[256]; - int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer)); + // int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer)); - in_buffer[n] = '\0'; - printf("Received message from server: '%s'\n", in_buffer); + // in_buffer[n] = '\0'; + //printf("Received message from server: '%s'\n", in_buffer); sock.close(); @@ -77,4 +77,3 @@ while(1) {} #endif } -