SimpleSocket 1.0 examples
Dependencies: EthernetNetIf SimpleSocket 1.0 mbed
Diff: echoclient.cpp
- Revision:
- 40:84182fc63956
- Parent:
- 39:108499af2b53
--- a/echoclient.cpp Wed Jun 06 03:34:16 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -#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"); -} \ No newline at end of file