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: EthernetInterface SimpleSocket mbed-rtos mbed
echoclient.cpp
00001 #include "SimpleSocket.h" 00002 00003 void echoclient() { 00004 printf("Echo server => "); 00005 char server[32]; 00006 scanf("%s", server); 00007 00008 ClientSocket socket(server, 1234); 00009 00010 if (socket) { 00011 char message[80] = {}; 00012 printf("Enter message => "); 00013 int c = 0; 00014 while (c < ' ' || 0x7E < c) 00015 c = getc(stdin); 00016 ungetc(c, stdin); 00017 for (int i = 0; i < sizeof(message) - 1 && (c = getc(stdin)) >= ' '; i++) 00018 message[i] = c; 00019 00020 socket.printf("%s\r\n", message); 00021 00022 // wait until data is received 00023 while (!socket.available()) 00024 ; 00025 printf("Received: "); 00026 00027 while (socket.available()) { 00028 char buf[128]; 00029 int len = socket.read(buf, sizeof(buf) - 1); 00030 buf[len] = '\0'; 00031 printf("%s", buf); 00032 } 00033 printf("\nClosing...\n"); 00034 socket.close(); 00035 } 00036 printf("Done.\n"); 00037 }
Generated on Mon Jul 18 2022 00:17:10 by
1.7.2