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@39:108499af2b53, 2012-06-06 (annotated)
- Committer:
- yamaguch
- Date:
- Wed Jun 06 03:34:16 2012 +0000
- Revision:
- 39:108499af2b53
updated link to the library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch | 39:108499af2b53 | 1 | #include "EthernetNetIf.h" |
yamaguch | 39:108499af2b53 | 2 | #include "SimpleSocket.h" |
yamaguch | 39:108499af2b53 | 3 | |
yamaguch | 39:108499af2b53 | 4 | void echoserver() { |
yamaguch | 39:108499af2b53 | 5 | EthernetNetIf eth; |
yamaguch | 39:108499af2b53 | 6 | eth.setup(); |
yamaguch | 39:108499af2b53 | 7 | |
yamaguch | 39:108499af2b53 | 8 | ServerSocket server(1234); |
yamaguch | 39:108499af2b53 | 9 | |
yamaguch | 39:108499af2b53 | 10 | while (true) { |
yamaguch | 39:108499af2b53 | 11 | ClientSocket socket = server.accept(); |
yamaguch | 39:108499af2b53 | 12 | if (socket) { |
yamaguch | 39:108499af2b53 | 13 | while (socket) { |
yamaguch | 39:108499af2b53 | 14 | char buf[80]; |
yamaguch | 39:108499af2b53 | 15 | int len = socket.read(buf, sizeof(buf)); |
yamaguch | 39:108499af2b53 | 16 | if (len > 0) |
yamaguch | 39:108499af2b53 | 17 | socket.write(buf, len); |
yamaguch | 39:108499af2b53 | 18 | } |
yamaguch | 39:108499af2b53 | 19 | socket.close(); |
yamaguch | 39:108499af2b53 | 20 | } |
yamaguch | 39:108499af2b53 | 21 | } |
yamaguch | 39:108499af2b53 | 22 | } |