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@17:50c0e9c5ca79, 2011-09-01 (annotated)
- Committer:
- yamaguch
- Date:
- Thu Sep 01 04:34:43 2011 +0000
- Revision:
- 17:50c0e9c5ca79
- Parent:
- 15:ae9aff693b07
- Child:
- 21:a3cf1f055a4d
changed accept API
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 |
13:1adb19edf716 | 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 |
13:1adb19edf716 | 17 | char buf[8]; |
yamaguch |
17:50c0e9c5ca79 | 18 | int len = socket.read(buf, sizeof(buf)); |
yamaguch |
13:1adb19edf716 | 19 | if (len > 0) |
yamaguch |
17:50c0e9c5ca79 | 20 | socket.write(buf, len); |
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 | } |