Basic SoftAP TCP Server Example
Implements a SoftAP TCP echo server
- SDK directory:
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 settings.ini is packaged with the App file and downloaded to the device.
This example implements a TCP echo server on the SoftAP network interface.
After installing and running the app, the SoftAP server runs and displays a message on the Gecko OS terminal similar to:
> Starting SoftAP... Softap name: TCP Server SoftAP Softap password: password Starting TCP Echo Server... TCP Echo Server listening on: tcp-server.com:2000
Connect a mobile device or computer to the Gecko OS Soft AP using the Softap name and password reported by the Gecko OS app.
Run a TCP client and connect to the TCP Echo Server using the name and port reported by the Gecko OS app.
The Gecko OS app logs the client MAC address and assigned IP to the terminal, for example:
[90:18:7C:34:CB:97 associated] > SoftAP Client: 90:18:7C:34:CB:97 (10.10.10.2) - Connected
When you send a message from the client to the server, the server logs the message received, e.g.
Rx data: hi
Then the server echoes the data back to the client.
("settings.ini")loads and runs the settings initialization file.
gos_tcp_register_server_event_handlers registers custom handlers for the events:
- client connect -
- client disconnect -
- client data receive -
- client connect -
gos_network_register_softap_event_handler registers a softap client connect/disconnect handler
- gos_tcp_listen starts the TCP server.
- Logs connect message to the Gecko OS terminal console.
- Logs disconnect message to the Gecko OS terminal console.
When client data is received:
- calls gos_tcp_read to read data into a buffer
- formats data, logs it to the Gecko OS terminal, and echoes it back to the client with gos_tcp_write