Simple code for comunication via TCP between the mbed and PC.
Dependencies: EthernetInterface SimpleSocket mbed-rtos mbed
Fork of SimpleSocketExamples by
Diff: examples/echoserver.cpp
- Revision:
- 0:6dc3cfd058c6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/echoserver.cpp Mon Feb 04 09:29:18 2013 +0000 @@ -0,0 +1,23 @@ +#include "SimpleSocket.h" + +void echoserver() +{ + ServerSocket server(1234); + + printf("server: %s:1234\n", EthernetInterface::getIPAddress()); + + while (true) { + ClientSocket socket = server.accept(); + + if (socket) { + while (socket) { + char buf[80]; + int len = socket.read(buf, sizeof(buf)); + if (len > 0) + socket.write(buf, len); + } + socket.close(); + } + wait(1.0); + } +} \ No newline at end of file