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.
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "TCPServer.h" 00004 #include "TCPSocket.h" 00005 00006 int main() 00007 { 00008 printf("TCP server example\n"); 00009 00010 EthernetInterface eth; 00011 eth.connect(); 00012 00013 printf("The Server IP address is '%s'\n", eth.get_ip_address()); 00014 00015 TCPServer srv; 00016 TCPSocket client_sock; 00017 SocketAddress client_addr; 00018 char *buffer = new char[256]; 00019 00020 /* Open the server on ethernet stack */ 00021 srv.open(ð); 00022 00023 /* Bind the HTTP port (TCP 80) to the server */ 00024 srv.bind(eth.get_ip_address(), 23); 00025 00026 /* Can handle x simultaneous connections */ 00027 srv.listen(1); 00028 00029 srv.accept(&client_sock, &client_addr); 00030 printf("Accepted %s:%d\n", client_addr.get_ip_address(), 00031 client_addr.get_port()); 00032 strcpy(buffer, "Hello \n\r"); 00033 client_sock.send(buffer, strlen(buffer)); 00034 client_sock.recv(buffer, 256); 00035 00036 client_sock.close(); 00037 delete[] buffer; 00038 }
Generated on Tue Jul 12 2022 19:51:22 by
1.7.2