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@10:62ce72ee3e91, 2011-08-18 (annotated)
- Committer:
- yamaguch
- Date:
- Thu Aug 18 08:46:47 2011 +0000
- Revision:
- 10:62ce72ee3e91
broken - httpclient gets less data
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yamaguch |
10:62ce72ee3e91 | 1 | #include "mbed.h" |
| yamaguch |
10:62ce72ee3e91 | 2 | #include "SimpleSocket.h" |
| yamaguch |
10:62ce72ee3e91 | 3 | |
| yamaguch |
10:62ce72ee3e91 | 4 | void echoclient(char *server, int port, char *message) { |
| yamaguch |
10:62ce72ee3e91 | 5 | ClientSocket socket(server, port); |
| yamaguch |
10:62ce72ee3e91 | 6 | while (!socket.connected()) |
| yamaguch |
10:62ce72ee3e91 | 7 | ; |
| yamaguch |
10:62ce72ee3e91 | 8 | printf("Connected to server\n"); |
| yamaguch |
10:62ce72ee3e91 | 9 | if (socket.connected()) { |
| yamaguch |
10:62ce72ee3e91 | 10 | socket.read();// dummy read |
| yamaguch |
10:62ce72ee3e91 | 11 | printf("Sending message\n"); |
| yamaguch |
10:62ce72ee3e91 | 12 | socket.writef("%s\n", message); |
| yamaguch |
10:62ce72ee3e91 | 13 | while (socket.connected()) { |
| yamaguch |
10:62ce72ee3e91 | 14 | if (socket.available()) { |
| yamaguch |
10:62ce72ee3e91 | 15 | char buf[128]; |
| yamaguch |
10:62ce72ee3e91 | 16 | int len = socket.read(buf, sizeof(buf)); |
| yamaguch |
10:62ce72ee3e91 | 17 | buf[len] = '\0'; |
| yamaguch |
10:62ce72ee3e91 | 18 | printf("Received from server: len = %d, %s\n", len, buf); |
| yamaguch |
10:62ce72ee3e91 | 19 | break; |
| yamaguch |
10:62ce72ee3e91 | 20 | } |
| yamaguch |
10:62ce72ee3e91 | 21 | } |
| yamaguch |
10:62ce72ee3e91 | 22 | } |
| yamaguch |
10:62ce72ee3e91 | 23 | printf("Done\n"); |
| yamaguch |
10:62ce72ee3e91 | 24 | } |