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/echoclient.cpp@12:52170a866d4a, 2011-08-19 (annotated)
- Committer:
- yamaguch
- Date:
- Fri Aug 19 02:17:01 2011 +0000
- Revision:
- 12:52170a866d4a
broken (echo client/echo server)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yamaguch |
12:52170a866d4a | 1 | #include "mbed.h" |
| yamaguch |
12:52170a866d4a | 2 | #include "SimpleSocket.h" |
| yamaguch |
12:52170a866d4a | 3 | |
| yamaguch |
12:52170a866d4a | 4 | void echoclient(char *server, int port, char *message) { |
| yamaguch |
12:52170a866d4a | 5 | printf("** echoclient **\n"); |
| yamaguch |
12:52170a866d4a | 6 | |
| yamaguch |
12:52170a866d4a | 7 | ClientSocket socket(server, port); |
| yamaguch |
12:52170a866d4a | 8 | |
| yamaguch |
12:52170a866d4a | 9 | for (int i = 0; i < 10; i++) { |
| yamaguch |
12:52170a866d4a | 10 | if (socket.connected()) { |
| yamaguch |
12:52170a866d4a | 11 | printf("Sending message: %s", message); |
| yamaguch |
12:52170a866d4a | 12 | socket.writef("%s\n", message); |
| yamaguch |
12:52170a866d4a | 13 | while (socket.connected()) { |
| yamaguch |
12:52170a866d4a | 14 | if (socket.available()) { |
| yamaguch |
12:52170a866d4a | 15 | char buf[128]; |
| yamaguch |
12:52170a866d4a | 16 | int len = socket.read(buf, sizeof(buf) - 1); |
| yamaguch |
12:52170a866d4a | 17 | buf[len] = '\0'; |
| yamaguch |
12:52170a866d4a | 18 | printf("Received from server: len = %d, %s\n", len, buf); |
| yamaguch |
12:52170a866d4a | 19 | break; |
| yamaguch |
12:52170a866d4a | 20 | } |
| yamaguch |
12:52170a866d4a | 21 | } |
| yamaguch |
12:52170a866d4a | 22 | } |
| yamaguch |
12:52170a866d4a | 23 | } |
| yamaguch |
12:52170a866d4a | 24 | |
| yamaguch |
12:52170a866d4a | 25 | printf("Closing socket\n"); |
| yamaguch |
12:52170a866d4a | 26 | socket.close(); |
| yamaguch |
12:52170a866d4a | 27 | printf("Done\n"); |
| yamaguch |
12:52170a866d4a | 28 | } |