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 mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 00004 #define MBED_DEV_IP "192.168.0.52" 00005 #define MBED_DEV_MASK "255.255.255.0" 00006 #define MBED_DEV_GW "0.0.0.0" 00007 #define ECHO_SERVER_PORT 5000 00008 00009 00010 int main (void) { 00011 EthernetInterface eth; 00012 eth.init(MBED_DEV_IP, MBED_DEV_MASK, MBED_DEV_GW); //Assign a device ip, mask and gateway 00013 eth.connect(); 00014 printf("IP Address is %s\n", eth.getIPAddress()); 00015 00016 TCPSocketServer server; 00017 server.bind(ECHO_SERVER_PORT); 00018 server.listen(); 00019 00020 while (true) { 00021 printf("\nWait for new connection...\n"); 00022 TCPSocketConnection client; 00023 server.accept(client); 00024 client.set_blocking(false, 1500); // Timeout after (1.5)s 00025 00026 printf("Connection from: %s\n", client.get_address()); 00027 char buffer[256]; 00028 while (true) { 00029 int n = client.receive(buffer, sizeof(buffer)); 00030 if (n <= 0) break; 00031 00032 client.send_all(buffer, n); 00033 if (n <= 0) break; 00034 } 00035 00036 client.close(); 00037 } 00038 }
Generated on Thu Jul 21 2022 12:43:04 by
1.7.2