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
echoclient.cpp
- Committer:
- yamaguch
- Date:
- 2012-06-06
- Revision:
- 39:108499af2b53
File content as of revision 39:108499af2b53:
#include "EthernetNetIf.h"
#include "SimpleSocket.h"
void echoclient() {
EthernetNetIf eth;
eth.setup();
printf("Echo server => ");
char server[32];
scanf("%s", server);
ClientSocket socket(server, 1234);
if (socket) {
char message[80] = {};
printf("Enter message => ");
int c = 0;
while (c < ' ' || 0x7E < c)
c = getc(stdin);
ungetc(c, stdin);
for (int i = 0; i < sizeof(message) - 1 && (c = getc(stdin)) >= ' '; i++)
message[i] = c;
socket.printf("%s", message);
// wait until data is received
while (!socket.available())
;
printf("Received: ");
while (socket.available()) {
char buf[128];
int len = socket.read(buf, sizeof(buf) - 1);
buf[len] = '\0';
printf("%s", buf);
}
printf("\nClosing...\n");
socket.close();
}
printf("Done.\n");
}