
This is an example based on mbed-os cellular APIs that demonstrates a TCP or UDP echo transaction with a public echo server.
Diff: main.cpp
- Revision:
- 42:cab443dff75e
- Parent:
- 40:c46ee5b71843
diff -r 1f13c9a6ee23 -r cab443dff75e main.cpp --- a/main.cpp Thu May 16 09:02:09 2019 +0100 +++ b/main.cpp Wed May 29 08:01:56 2019 +0100 @@ -173,7 +173,7 @@ sock.set_timeout(15000); #if MBED_CONF_APP_SOCK_TYPE == NONIP - retcode = sock.send((void*) echo_string, sizeof(echo_string)); + retcode = sock.send((void*) echo_string, strlen(echo_string)); if (retcode < 0) { print_function("CellularNonIPSocket.send() fails, code: %d\n", retcode); return -1; @@ -202,7 +202,7 @@ } else { print_function("TCP: connected with %s server\n", host_name); } - retcode = sock.send((void*) echo_string, sizeof(echo_string)); + retcode = sock.send((void*) echo_string, strlen(echo_string)); if (retcode < 0) { print_function("TCPSocket.send() fails, code: %d\n", retcode); return -1; @@ -213,7 +213,7 @@ n = sock.recv((void*) recv_buf, sizeof(recv_buf)); #else - retcode = sock.sendto(sock_addr, (void*) echo_string, sizeof(echo_string)); + retcode = sock.sendto(sock_addr, (void*) echo_string, strlen(echo_string)); if (retcode < 0) { print_function("UDPSocket.sendto() fails, code: %d\n", retcode); return -1;