Jump to main content

##

# 1.9 TCP/IP TCP and UDP Client Server

The TCP/IP TCP & UDP Client Server configuration demonstrates creating a network client and a network server that uses both TCP and UDP socket APIs respectivly.

TCP/IP TCP and UDP Client Server MCC Configuration

The following Project Graph diagram shows the Harmony components included in the TCP/IP TCP and UDP Client Server demo application.

- MCC is launched by selecting Tools > Embedded > MPLAB® Code Configurator from the MPLAB X IDE and after opening the project, TCP/IP demo project is ready to be configured and regenerated.

- TCP/IP Root Layer Project Graph

  The root layer project shows that USART1 peripheral is selected to do read and write operation for TCP/IP commands.

  This is the basic configuration with SYS_CONSOLE, SYS_DEBUG and SYS_COMMAND modules. These modules are required for TCP/IP command execution.

  FreeRTOS component is required for RTOS application.

  TCP sockets calculate the ISN using the wolfSSL crypto library.

- TCP/IP Configuration

  1. SAM E70 Xplained Ultra

- TCP/IP Required Application

  TCP/IP demo use these application module components for this demo.

  Announce module to discover the Microchip devices within a local network.

  DHCP Client module to discover the IPv4 address from the nearest DHCP Server.

  DNS Client provides DNS resolution capabilities to the stack.

  SNTP Simple Network Time Protocol updates its internal time periodically using a pool of public global time servers.

- TCPIP Data Link Layer

  Internal ethernet driver(gmac) is enabled with the external LAN8740 PHY driver library for SAME70 demonstartion.

  The MIIM Driver supports asynchronous read/write and scan operations for accessing the external PHY registers and notification when MIIM operations have completed.

TCP/IP TCP and UDP Client Server Hardware Configuration

This section describes the hardware configuration for ATSAM E70 Xplained Ultra Evaluation Kit and one can be used for the respective application demonstration.

1. This section describes the required default hardware configuration use SAM E70 Xplained Ultra Evaluation Kit

   - Ensure ERASE jumper is Open.

   - Open the J805 Jumper

   - Refer to the SAM E70 Xplained Ultra User Guide

   - Insert the LAN8740 PHY daughter board on the ETHERNET PHY MODULE header.

   - Connect the micro USB cable from the computer to the DEBUG USB connector on the SAM E70 Xplained Ultra Evaluation Kit

   - Establish a connection between the router/switch with the SAM E70 Xplained Ultra Evaluation Kit through the RJ45 connector

TCP/IP TCP and UDP Client Server Running Application

The Client Server configuration use combination of both TCP and UDP sockets for both client and server communication.

This table list the name and location of the MPLAB X IDE project folder for the demonstration.

Project Name | Target Device | Target Development Board | Description
--- | --- | --- | ---
sam_e70_xult_freertos.X | ATSAME70Q21B | SAME70 Xplained Ultra + LAN8740 PHY Daughter board | Demonstrates the TCP/IP TCP and UDP Client Server on development board with ATSAME70Q21B device and LAN8740 PHY daughter board. This implementation is based on FreeRTOS.

Running Demonstration Steps

1. Build and download the demonstration project on the target board.

2. If the board has a UART connection:

   1. A virtual COM port will be detected on the computer, when the USB cable is connected to USB-UART connector.

   2. Open a standard terminal application on the computer (like Hyper-terminal or Tera Term) and configure the virtual COM port.

   3. Set the serial baud rate to 115200 baud in the terminal application.

   4. See that the initialization prints on the serial port terminal.

   5. When the DHCP client is enabled in the demonstration, wait for the DHCP server to assign an IP address for the development board. This will be printed on the serial port terminal.

      - Alternatively: Use the Announce service or ping to get the IP address of the board.

      - Run tcpip_discoverer.jar to discover the IPv4 and IPv6 address for the board.

3. Execution :

   1. Once the demonstration starts executing, we can observe the current IP settings at the Tera Term terminal port.

   2. Using "help" will display the available commands that can be used for this demo.

   3. The application can create 4 separate connections, each one running in its own thread:

      - A TCP client connection
      - A TCP server connection
      - A UDP client connection
      - A UDP server connection

   4. Each connection has its own set of commands.

      - They can open or close the sockets, send messages to the socket they are connected to, they can display the received messages, etc.

      - Using your preferred networking tools on the PC side ( netcat, Packet Sender, Hercules, python scripts, etc ) create sockets that talk to the ones opened by the client server application.

      - This way you can exchange data with any/all of the communication threads that the demonstration creates.

   5. After the successful broad bring up, the console output becomes

   6. 'help' command will display the available application commands.

   7. Hence, TCP and UDP Client test & Server test can be performed by using these commands using your preferred networking tools on the PC side ( netcat, Packet Sender, Hercules, python scripts, etc )