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@15:ae9aff693b07, 2011-08-19 (annotated)
- Committer:
- yamaguch
- Date:
- Fri Aug 19 05:18:29 2011 +0000
- Revision:
- 15:ae9aff693b07
- Parent:
- 14:c6f5c0833cee
- Child:
- 24:9c7a2e830ef6
published as 0.92
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yamaguch |
15:ae9aff693b07 | 1 | #include "mbed.h" |
| yamaguch |
15:ae9aff693b07 | 2 | #include "SimpleSocket.h" |
| yamaguch |
15:ae9aff693b07 | 3 | |
| yamaguch |
15:ae9aff693b07 | 4 | void echoclient(char *server, int port, char *message) { |
| yamaguch |
15:ae9aff693b07 | 5 | printf("** echoclient, server = %s, port = %d, message = %s\n", server, port, message); |
| yamaguch |
15:ae9aff693b07 | 6 | |
| yamaguch |
15:ae9aff693b07 | 7 | ClientSocket socket(server, port); |
| yamaguch |
15:ae9aff693b07 | 8 | |
| yamaguch |
15:ae9aff693b07 | 9 | if (socket.connected()) { |
| yamaguch |
15:ae9aff693b07 | 10 | socket.writef(message); |
| yamaguch |
15:ae9aff693b07 | 11 | |
| yamaguch |
15:ae9aff693b07 | 12 | // wait until data is received |
| yamaguch |
15:ae9aff693b07 | 13 | while (!socket.available()) |
| yamaguch |
15:ae9aff693b07 | 14 | ; |
| yamaguch |
15:ae9aff693b07 | 15 | printf("Received: "); |
| yamaguch |
15:ae9aff693b07 | 16 | |
| yamaguch |
15:ae9aff693b07 | 17 | while (socket.available()) { |
| yamaguch |
15:ae9aff693b07 | 18 | char buf[128]; |
| yamaguch |
15:ae9aff693b07 | 19 | int len = socket.read(buf, sizeof(buf) - 1); |
| yamaguch |
15:ae9aff693b07 | 20 | buf[len] = '\0'; |
| yamaguch |
15:ae9aff693b07 | 21 | printf(buf); |
| yamaguch |
15:ae9aff693b07 | 22 | } |
| yamaguch |
15:ae9aff693b07 | 23 | printf("Closing...\n"); |
| yamaguch |
15:ae9aff693b07 | 24 | socket.close(); |
| yamaguch |
15:ae9aff693b07 | 25 | } |
| yamaguch |
15:ae9aff693b07 | 26 | printf("Done.\n"); |
| yamaguch |
14:c6f5c0833cee | 27 | } |