This is the documentation for the latest (main) development branch. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

TCP Client

Overview

The application creates a TCP socket and tries to connect to the server with predefined IP address and port number. When a connection is successfully established, the application sends message and waits for the answer. After the server’s reply, application prints received reply as ASCII text, waits for 2 seconds and sends another message.

There are many host-side tools which can be used to interact with the UDP/TCP server/client. Only the netcat tool is used here as an example for send and receive many kinds of packets. Note: please replace 192.168.3.220 3333 with desired IPV4/IPV6 address and port number in the following command.

TCP server using netcat

nc -l 192.168.3.220 3333

Requirements

  1. A working AP is required.

  2. Configure WiFi SSID and WiFi Password in menuconfig.

  3. Configure the IPV4 Address and Port in menuconfig.

Building and flashing

Example Location: examples/network/sockets/tcp_client

compile, burn, and more, see: get started

Running result

Successfully running will output the following logs

I/wm_nm_core      [5.020] got ip: 192.168.3.208
D/wm_nm_core      [5.024] WM_NM_EV post event 4 success
I/tcp-client      [5.530] wifi station start success, network is ready!
I/tcp client      [5.538] Socket created, connecting to 192.168.3.220:3333
I/tcp client      [5.638] Successfully connected
I/tcp client      [38.166] Received 6 bytes from 192.168.3.220:
I/tcp client      [38.172] hello

I/tcp client      [44.882] Received 4 bytes from 192.168.3.220:
I/tcp client      [44.888] bye