tcp_socket lab
Dependencies: mbed mbed-rtos EthernetInterface
Diff: main.cpp
- Revision:
- 7:a5ead1402704
- Parent:
- 3:36fd3cfad85a
- Child:
- 8:23b1fba109b0
diff -r 5dae237341f7 -r a5ead1402704 main.cpp --- a/main.cpp Tue Jun 04 16:07:06 2013 +0100 +++ b/main.cpp Mon May 04 22:47:02 2015 +0000 @@ -7,7 +7,7 @@ EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); - printf("IP Address is %s\n", eth.getIPAddress()); + printf("\nServer IP Address is %s\n", eth.getIPAddress()); TCPSocketServer server; server.bind(ECHO_SERVER_PORT); @@ -25,6 +25,22 @@ int n = client.receive(buffer, sizeof(buffer)); if (n <= 0) break; + // print received message to terminal + buffer[n] = '\0'; + printf("Received message from Client :'%s'\n",buffer); + + // reverse the message + char temp; + for(int f = 0, l = n-1; f<l; f++,l--){ + temp = buffer[f]; + buffer[f] = buffer[l]; + buffer[l] = temp; + } + + // print reversed message to terminal + printf("Sending message to Client: '%s'\n",buffer); + + // Echo received message back to client client.send_all(buffer, n); if (n <= 0) break; }