Basic SoftAP TCP Server Example
Implements a SoftAP TCP echo server
- SDK directory:
apps/basic/softap_tcp_server
- Zentri App Store:
ZENTRI-BASOFTAPTCPS
API Features Demonstrated
Platforms
This app works on:
- AMW004 - Zentri Mackerel evaluation board
- AMW106 - Zentri Moray evaluation board
- NXP-SCCK
Requirements and Prerequisites
This app requires a ZentriOS device, such as an AMWx06-E03 (Moray) evaluation board.
Resources
The initialization file settings.ini is packaged with the .zap
file and downloaded to the device.
Description
This example implements a TCP echo server on the SoftAP network interface.
Usage Instructions
After installing and running the app, the SoftAP server runs and displays a message on the ZentriOS 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 ZentriOS Soft AP using the Softap name and password reported by the ZentriOS app.
Run a TCP client and connect to the TCP Echo Server using the name and port reported by the ZentriOS app.
The ZentriOS 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.
Implementation
zn_app_init
zn_load_app_settings
("settings.ini")
loads and runs the settings initialization file.zn_tcp_register_server_event_handlers registers custom handlers for the events:
- client connect -
tcp_client_connect_handler
- client disconnect -
tcp_client_disconnect_handler
- client data receive -
tcp_client_receive_handler
- client connect -
zn_network_register_softap_event_handler registers a softap client connect/disconnect handler
softap_event_handler
.- zn_tcp_listen starts the TCP server.
tcp_client_connect_handler
- Logs connect message to the ZentriOS terminal console.
tcp_client_disconnect_handler
- Logs disconnect message to the ZentriOS terminal console.
tcp_client_receive_handler
When client data is received:
- calls zn_tcp_read to read data into a buffer
- formats data, logs it to the ZentriOS terminal, and echoes it back to the client with zn_tcp_write
Source
See:
See also: