Basic TCP Client Example

A TCP client that transmits sensor data to a remote TCP server

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.


This app connects to the Zentri test echo server at, and transmits GPIO data. Data is echoed back to the app and printed on the Gecko OS terminal.

Usage Instructions

Open a Gecko OS serial terminal to the device. See Getting Started, Opening a Gecko OS Terminal.

This app assumes your Gecko OS device is set up with the credentials to join your local network. If you have not already set up network credentials, on the Gecko OS terminal, run the commands:

network_up -s

See the Wi-Fi Command API documentation for network_up and save.

No interaction is required. Output is similar to:

> Network is down - Restarting Network...

Attempting to connect to
Connected. Socket handle: 0
Network down
Network up
Attempting to connect to
Connected. Socket handle: 1
Rx data: gpios:F5DA
Rx data: gpios:35DA
Rx data: gpios:35DE


In gos_app_init:

In wlan_network_event_handler:

The tcp_attempt_connect_handler function, in response to the tcp_attempt_connect_handler event:

The tcp_disconnect_handler function, in response to a TCP disconnection event:

The tcp_receive_handler function, in response to a data received event:

Note that the data received is echoed from the Gecko OS echo server.

The tcp_transmit_handler function, in response to a periodic tcp_transmit_handler event,