Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf SimpleSocket 1.0 mbed
Example/echoserver.cpp
- Committer:
- yamaguch
- Date:
- 2011-09-01
- Revision:
- 17:50c0e9c5ca79
- Parent:
- 15:ae9aff693b07
- Child:
- 21:a3cf1f055a4d
File content as of revision 17:50c0e9c5ca79:
#include "mbed.h" #include "SimpleSocket.h" void blink(DigitalOut& led, Timer& timer, float interval = 1.0); int echoserver(int port) { printf("** echoserver, port = %d\n", port); DigitalOut led1(LED1), led2(LED2); ServerSocket server(port); Timer timer; timer.start(); while (true) { if (ClientSocket socket = server.accept()) { while (socket.connected()) { char buf[8]; int len = socket.read(buf, sizeof(buf)); if (len > 0) socket.write(buf, len); blink(led1, timer); } socket.close(); } blink(led2, timer); } }