mbed_example
/
mbed-os-example-tcp-server
TCP Server application which accepts single TCP telnet client connection
Revision 0:ddb5698aa782, committed 2017-10-30
- Comitter:
- deepikabhavnani
- Date:
- Mon Oct 30 16:59:55 2017 +0000
- Commit message:
- TCP Sever example
Changed in this revision
diff -r 000000000000 -r ddb5698aa782 .gitignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Mon Oct 30 16:59:55 2017 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
diff -r 000000000000 -r ddb5698aa782 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Mon Oct 30 16:59:55 2017 +0000 @@ -0,0 +1,9 @@ +### Getting started with the TCPServer API ### + +TCPServer Example +TCP sever in this application accepts single telnet client connection and sends +buffer data. + +**Note:** The current example is limited to the ethernet interface on supported +devices. To use the example with a different interface, you will need to modify +main.cpp and replace the EthernetInterface class with the appropriate interface. \ No newline at end of file
diff -r 000000000000 -r ddb5698aa782 img/uvision.png Binary file img/uvision.png has changed
diff -r 000000000000 -r ddb5698aa782 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Oct 30 16:59:55 2017 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "TCPServer.h" +#include "TCPSocket.h" + +int main() +{ + printf("TCP server example\n"); + + EthernetInterface eth; + eth.connect(); + + printf("The Server IP address is '%s'\n", eth.get_ip_address()); + + TCPServer srv; + TCPSocket client_sock; + SocketAddress client_addr; + char *buffer = new char[256]; + + /* Open the server on ethernet stack */ + srv.open(ð); + + /* Bind the HTTP port (TCP 80) to the server */ + srv.bind(eth.get_ip_address(), 23); + + /* Can handle x simultaneous connections */ + srv.listen(1); + + srv.accept(&client_sock, &client_addr); + printf("Accepted %s:%d\n", client_addr.get_ip_address(), + client_addr.get_port()); + strcpy(buffer, "Hello \n\r"); + client_sock.send(buffer, strlen(buffer)); + client_sock.recv(buffer, 256); + + client_sock.close(); + delete[] buffer; +}
diff -r 000000000000 -r ddb5698aa782 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Mon Oct 30 16:59:55 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#e62a1b9236b44e70ae3b0902dc538481c04d455b