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@8:b35559c14d17, 2011-08-17 (annotated)
- Committer:
- yamaguch
- Date:
- Wed Aug 17 05:30:35 2011 +0000
- Revision:
- 8:b35559c14d17
- Parent:
- 7:d57efbdb6517
- Child:
- 10:62ce72ee3e91
fixed w/ a workaround for name \printf\ issue
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 "EthernetNetIf.h" |
yamaguch |
4:59056313fbfa | 3 | #include "SimpleSocket.h" |
yamaguch |
4:59056313fbfa | 4 | |
yamaguch |
8:b35559c14d17 | 5 | int echoserver(int port) { |
yamaguch |
4:59056313fbfa | 6 | DigitalOut led1(LED1); |
yamaguch |
4:59056313fbfa | 7 | DigitalOut led2(LED2); |
yamaguch |
4:59056313fbfa | 8 | |
yamaguch |
8:b35559c14d17 | 9 | ServerSocket server(port); |
yamaguch |
4:59056313fbfa | 10 | |
yamaguch |
4:59056313fbfa | 11 | Timer timer; |
yamaguch |
4:59056313fbfa | 12 | timer.start(); |
yamaguch |
4:59056313fbfa | 13 | |
yamaguch |
4:59056313fbfa | 14 | while (true) { |
yamaguch |
4:59056313fbfa | 15 | if (ClientSocket *clientSocket = server.accept()) { |
yamaguch |
4:59056313fbfa | 16 | while (clientSocket->connected()) { |
yamaguch |
4:59056313fbfa | 17 | char buf[8]; |
yamaguch |
4:59056313fbfa | 18 | int len = clientSocket->read(buf, sizeof(buf)); |
yamaguch |
4:59056313fbfa | 19 | if (len > 0) |
yamaguch |
4:59056313fbfa | 20 | clientSocket->write(buf, len); |
yamaguch |
4:59056313fbfa | 21 | |
yamaguch |
4:59056313fbfa | 22 | if (timer.read() > 10) { |
yamaguch |
4:59056313fbfa | 23 | timer.reset(); |
yamaguch |
4:59056313fbfa | 24 | timer.start(); |
yamaguch |
4:59056313fbfa | 25 | led1 = !led1; |
yamaguch |
4:59056313fbfa | 26 | } |
yamaguch |
4:59056313fbfa | 27 | } |
yamaguch |
4:59056313fbfa | 28 | } |
yamaguch |
4:59056313fbfa | 29 | if (timer.read() > 1) { |
yamaguch |
4:59056313fbfa | 30 | timer.reset(); |
yamaguch |
4:59056313fbfa | 31 | timer.start(); |
yamaguch |
4:59056313fbfa | 32 | led2 = !led2; |
yamaguch |
4:59056313fbfa | 33 | } |
yamaguch |
4:59056313fbfa | 34 | } |
yamaguch |
4:59056313fbfa | 35 | } |