This application uses the WiConnect TCP client command to open a TCP connection to a TCP echo server on the internet.
The TCP echo server, located on the internet at
test.zentri.com:50007, simply echoes all received data back to the WiConnect TCP client.
Once the connection is established, stream_write is used to send data to the connection stream.
With all data sent, stream_poll is used to check for received data on the connection stream, and stream_read is used to read data waiting on the stream.
You will only need one ACKme evaluation board for this example.
Let's get started by connecting your board to a Wi-Fi network and opening the TCP connection stream. You can simply cut and paste the commands in the following table, but DON'T FORGET to replace your Wi-Fi network name and password for the defaults.
There is no need to bring up the WLAN network interface prior to opening a TCP connection, the TCP client (just like all commands that need the network) automatically connects to the network if a connection has not already been established.
An example showing what the session looks like if you entered the above commands successfully is shown below. Notice that the new TCP connection is assigned a stream handle, starting at 0 for the first TCP connection.
|Session log when opening the TCP client connection|
Check the status of open stream before continuing. Use the stream_list command to get a list of open streams. The number in brackets appended to each line is the local port used for the TCP connection stream.
> stream_list !# Type Info #0 TCPC test.zentri.com:50007 (41713)
Writing data to a stream is easy using the stream_write command. Copy and paste the following commands to write data to the open stream.
Checking for Data
To check for data on any stream (or all streams at once), use the stream_poll command as shown in the following session. If you don't want to poll for data, try assigning a GPIO to a stream to indicate when data is available. The tcp_client command describes how to assign a GPIO.
|Checking for data|
To read available data from any stream, use the stream_read command as shown in the following session. The following example reads up to 100 bytes from the stream.
|Checking for data|
|2015-Feb-14||Changed the example to use the test.zentri.com:50007 server||1.1+|