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@14:c6f5c0833cee, 2011-08-19 (annotated)
- Committer:
- yamaguch
- Date:
- Fri Aug 19 02:42:57 2011 +0000
- Revision:
- 14:c6f5c0833cee
- Child:
- 15:ae9aff693b07
fixed
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yamaguch |
14:c6f5c0833cee | 1 | #include "mbed.h" |
| yamaguch |
14:c6f5c0833cee | 2 | #include "SimpleSocket.h" |
| yamaguch |
14:c6f5c0833cee | 3 | |
| yamaguch |
14:c6f5c0833cee | 4 | void echoclient(char *server, int port, char *message) { |
| yamaguch |
14:c6f5c0833cee | 5 | |
| yamaguch |
14:c6f5c0833cee | 6 | ClientSocket client(server, port); |
| yamaguch |
14:c6f5c0833cee | 7 | // wait(1); |
| yamaguch |
14:c6f5c0833cee | 8 | // Net::poll(); |
| yamaguch |
14:c6f5c0833cee | 9 | //TCPSOCKET_CONNECTED: Connected to host. |
| yamaguch |
14:c6f5c0833cee | 10 | if (client.connected()) { |
| yamaguch |
14:c6f5c0833cee | 11 | // wait(1); |
| yamaguch |
14:c6f5c0833cee | 12 | // Net::poll(); |
| yamaguch |
14:c6f5c0833cee | 13 | // wait(1); |
| yamaguch |
14:c6f5c0833cee | 14 | // Net::poll(); |
| yamaguch |
14:c6f5c0833cee | 15 | printf("*** send: %s", message); |
| yamaguch |
14:c6f5c0833cee | 16 | client.writef(message); |
| yamaguch |
14:c6f5c0833cee | 17 | printf("*** sent: %s", message); |
| yamaguch |
14:c6f5c0833cee | 18 | //TCPSOCKET_WRITEABLE: Can write data to buf. |
| yamaguch |
14:c6f5c0833cee | 19 | //TCPSOCKET_READABLE: Data in buf. |
| yamaguch |
14:c6f5c0833cee | 20 | |
| yamaguch |
14:c6f5c0833cee | 21 | int total = 0; |
| yamaguch |
14:c6f5c0833cee | 22 | while (client.connected()) { |
| yamaguch |
14:c6f5c0833cee | 23 | if (client.available()) { |
| yamaguch |
14:c6f5c0833cee | 24 | char buf[129]; |
| yamaguch |
14:c6f5c0833cee | 25 | int len = client.read(buf, sizeof(buf) - 1); |
| yamaguch |
14:c6f5c0833cee | 26 | buf[len] = '\0'; |
| yamaguch |
14:c6f5c0833cee | 27 | printf(buf); |
| yamaguch |
14:c6f5c0833cee | 28 | total += len; |
| yamaguch |
14:c6f5c0833cee | 29 | } |
| yamaguch |
14:c6f5c0833cee | 30 | } |
| yamaguch |
14:c6f5c0833cee | 31 | printf("\n\n*** Total %d ***\n", total); |
| yamaguch |
14:c6f5c0833cee | 32 | } |
| yamaguch |
14:c6f5c0833cee | 33 | } |