![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A small example of TCP server over ethernet for mbed-os.
Diff: main.cpp
- Revision:
- 1:ec61ea9f67de
- Parent:
- 0:6e8275981824
- Child:
- 3:48f60b2918aa
--- a/main.cpp Thu Sep 22 11:20:29 2016 +0000 +++ b/main.cpp Mon Nov 14 15:34:13 2016 +0000 @@ -1,5 +1,5 @@ -#if !FEATURE_IPV4 - #error [NOT_SUPPORTED] IPV4 not supported for this target +#if !FEATURE_LWIP + #error [NOT_SUPPORTED] LWIP not supported for this target #endif #include "mbed.h" @@ -35,7 +35,7 @@ TCPServer srv; TCPSocket clt_sock; - //SocketAddress clt_addr; + SocketAddress clt_addr; /* Open the server on ethernet stack */ srv.open(ð); @@ -47,11 +47,8 @@ srv.listen(5); while (true) { - // Will be possible in releaseb 126 - //srv.accept(&clt_sock, &clt_addr); - //printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); - srv.accept(&clt_sock); - printf("new client accepted\n"); + srv.accept(&clt_sock, &clt_addr); + printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); clt_sock.send(HTTP_RESPONSE, strlen(HTTP_RESPONSE)); } }