Basic TCP Echo Server Example

Demonstrates a TCP server that echoes back all data received from clients.

API Features Demonstrated


This app works on:

Requirements and Prerequisites

Requires a Gecko OS evaluation board, such as a WGM160P_eval.

Other Gecko OS hardware can also be used by changing the source of the logged data to suit your device.


The initialization file resources/settings.ini is packaged with the app and downloaded to the device.


Demonstrates a TCP server that echoes back all data received from clients.

The gos_app_init function registers a handler for the TCP receive event, as well as for the client connect and disconnect events and the network event.

In the tcp_client_receive_handler, on receiving data, the handler polls the client stream to determine the received bytes. It then reads the stream, up to the maximum allowed read length, then echoes the read bytes back to the client.

Run the App first, then run the resources/ python script on your computer. As the script describes itself:

This script randomly opens and closes TCP server clients.
When the client socket is opened, it randomly blasts data.

You must supply the UUID of the device with the script --uuid option.

You can obtain the UUID by issuing the following command at the Gecko OS terminal:

> get system.uuid

The script discovers the device matching the supplied UUID using the Gecko OS broadcast feature, then reports the TCP server found. It then generates clients and client data to exercise the TCP echo server.

Status messages appear at the Gecko OS terminal for the App, and at the computer console on which the python script is running.