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
echoserver.cpp@25:b3ab82301345, 2011-09-12 (annotated)
- Committer:
- yamaguch
- Date:
- Mon Sep 12 06:50:42 2011 +0000
- Revision:
- 25:b3ab82301345
- Parent:
- Example/echoserver.cpp@22:fc886208c19b
- Child:
- 26:6f42de9d8ed8
set readable initial value to true; rename tcpeventhandler
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch |
4:59056313fbfa | 1 | #include "mbed.h" |
yamaguch |
4:59056313fbfa | 2 | #include "SimpleSocket.h" |
yamaguch |
4:59056313fbfa | 3 | |
yamaguch |
15:ae9aff693b07 | 4 | void blink(DigitalOut& led, Timer& timer, float interval = 1.0); |
yamaguch |
15:ae9aff693b07 | 5 | |
yamaguch |
8:b35559c14d17 | 6 | int echoserver(int port) { |
yamaguch |
15:ae9aff693b07 | 7 | printf("** echoserver, port = %d\n", port); |
yamaguch |
22:fc886208c19b | 8 | |
yamaguch |
15:ae9aff693b07 | 9 | DigitalOut led1(LED1), led2(LED2); |
yamaguch |
8:b35559c14d17 | 10 | ServerSocket server(port); |
yamaguch |
4:59056313fbfa | 11 | Timer timer; |
yamaguch |
4:59056313fbfa | 12 | timer.start(); |
yamaguch |
4:59056313fbfa | 13 | |
yamaguch |
4:59056313fbfa | 14 | while (true) { |
yamaguch |
17:50c0e9c5ca79 | 15 | if (ClientSocket socket = server.accept()) { |
yamaguch |
17:50c0e9c5ca79 | 16 | while (socket.connected()) { |
yamaguch |
22:fc886208c19b | 17 | if (socket.available()) { |
yamaguch |
22:fc886208c19b | 18 | int c = socket.read(); |
yamaguch |
22:fc886208c19b | 19 | socket.write(c); |
yamaguch |
22:fc886208c19b | 20 | } |
yamaguch |
15:ae9aff693b07 | 21 | blink(led1, timer); |
yamaguch |
4:59056313fbfa | 22 | } |
yamaguch |
17:50c0e9c5ca79 | 23 | socket.close(); |
yamaguch |
4:59056313fbfa | 24 | } |
yamaguch |
15:ae9aff693b07 | 25 | blink(led2, timer); |
yamaguch |
4:59056313fbfa | 26 | } |
yamaguch |
4:59056313fbfa | 27 | } |