Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

Implementing TCP Server/Client Using AnyCloud Libraries

Implementing TCP Server/Client Using AnyCloud Libraries

VaisakhK_66
Employee
Employee
10 replies posted 5 replies posted First question asked

Recently, ModusToolbox added a new set of connectivity software libraries called AnyCloud. Together, they enable seamless development of Wi-Fi and BLE based connectivity projects with the PSoC 6 MCU and CYW43xx Wi-Fi + Bluetooth combo devices. AnyCloud is a framework for IoT application development that is not tied to a specific cloud provider or management tool.

In this blog post, we will see how to configure PSoC 6 MCU as a TCP client and a TCP server using the AnyCloud libraries.

TCP/IP protocol is a communication standard that defines how to establish and maintain a network conversation between two parties in a network. The TCP/IP protocol is based on client-server model. TCP is used for organizing data in a way that guarantees the integrity of data sent over the network, regardless of the amount. Hence, this protocol is used to transmit data from other higher-level protocols (such as HTTP, FTP etc.) that require all transmitted data to arrive.

Network communication using the TCP/IP protocol typically involves creation of a socket, through which information exchange takes place between two connected parties in a network. You can consider socket similar to a door having an address and a door number. Similarly, a socket has a unique combination of an address (IP address) and a number (port number).

This TCP client and server implementation makes use of two AnyCloud libraries – Secure Sockets and Wi-Fi Connection Manger libraries.

The Secure Sockets library significantly simplifies the task of creating a socket and managing the network communication. It abstracts out the popular network stack lwIP and the secure library MbedTLS, thus enabling you to establish a secure connection. AnyCloud also offers a Wi-Fi Connection Manager (WCM) which makes Wi-Fi connections easier and more reliable. WCM provides an easy-to-use API to scan and connect. It also manages and preserves the Wi-Fi connection in a background thread.

Figure1.png

 

The basic steps involved in a TCP client operation are follows:

  1. Create a TCP socket
  2. Connect to a TCP socket on a remote host.
  3. Send and receive data
  4. Close the connection.

 

The basic steps involved in a TCP server operation are follows:

  1. Create a TCP socket
  2. Bind and listen to the TCP socket
  3. Accept incoming client connection
  4. Send and receive data
  5. Close the connection.

 

As part of the whole AnyCloud Solution, we have code examples demonstrating the basic steps required to set up a TCP client and a TCP server using the PSoC 6 MCU and CYW43xxx connectivity devices. You can try out these examples on Wi-Fi enabled kits such as

  1. PSoC 6 Wi-Fi BT Prototyping Kit (CY8CPROTO-062-4343W) - prototyping style kit with PSoC 6 device with 1MB flash and CYW4343W Wi-Fi + Bluetooth combo device.
  2. PSoC 62S2 Wi-Fi BT Pioneer Kit (CY8CKIT-062S2-43012) – pioneer kit with PSoC 6 device with 2 MB flash and CYW43012 Wi-Fi + Bluetooth combo device.

 

In the TCP client example, PSoC 6 MCU is configured as a TCP client, which establishes a connection with a remote TCP server and, based on the command received from the TCP server, turns the user LED ON or OFF. In the TCP server example, server establishes a connection with a TCP client. Once the connection completes successfully, the server allows the user to send LED ON/OFF command to the TCP client and the client responds by sending an acknowledgement message to the server.

To understand better on how to use the AnyCloud and the TCP client/server examples, you can start exploring the examples in the GitHub repository. To access the code examples:

  • Download ModusToolbox 2.1 IDE. You can download the setup from this link
  • Open ModusToolbox 2.1 IDE
  • Click the New Application link in the Quick Panel (or, use File > New > ModusToolbox Application.

Figure3.png

  • Pick a kit supported by the code example from the list shown in the Project Creator - Choose Board Support Package (BSP) dialog.

 

Figure3.png

  • In the Project Creator - Select Application dialog, choose the example: for client examples choose AnyCloud TCP Client, for server example choose AnyCloud TCP Server.

Figure4.png

 

  • Click on Create to complete the application creation process.

You can follow the instructions given in the example README.md file to understand the operation. If you have more than two Wi-Fi enabled kits as listed previously, you can try out TCP server example on one kit and TCP client example on the other kit. Also feel free to explore the source code and let us know your thoughts!

For more AnyCloud examples, refer to Cypress GitHub repository.

0 Likes
1172 Views
Authors