Jump to main content

##

# 1.8 TCP/IP UDP Client Server

This demonstration is a combination of the UDP Client and UDP Server application.

It shows the usage of MPLAB Harmony UDP API to implement,

- a UDP echo server on port 9760.
- a UDP client that establishes TCP/IP connection to a UDP server, on port 9760

## Description

The TCP/IP UDP Client Server application is based on MPLAB® Harmony 3 TCP/IP Stack.

The Harmony TCP/IP stack is a collection of different network protocols.

The source files of Harmony 3 TCP/IP stack is available here.

The demo is created with MPLAB X IDE and MCC plugin.

MCC Project Graph - TCP/IP UDP Client Server

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

Figure 1-22.Project Graph

FreeRTOS component is required for RTOS application. For bare-metal (non-RTOS) FreeRTOS component should not be selected.

NOTE - The above diagram contains FreeRTOS component and that is required for RTOS application. For bare-metal(non-RTOS) FreeRTOS component shouldn't be selected.

TCP/IP Configuration - TCP/IP UDP Client Server

The TCP/IP modules enabled for the demo is shown in the TCP/IP Configuration Overview

More details of TCP/IP Configuration plugin is available here

Figure 1-23.TCP/IP Configuration

The Application Layer modules enabled in the demo are as follows:

- Application Layer Modules
  - DHCP Client to discover the IPv4 address from the nearest DHCP Server.
  - DNS Client provides DNS resolution capabilities to the stack.

## Downloading and Building the application

To clone or download this application from Github, go to the repository and search for this device and then click Clone button to clone this repository or download as zip file.

This content can also be downloaded using content manager by following these instructions.

Path of the application within the repository is apps\tcpip_udp_client_server\firmware .

To build the application, refer to the following list of demo configurations and open the project using MPLAB X IDE.

Table 1-9.Demo Configurations
Project Name | Target Device | Development Board | Description
--- | --- | --- | ---
pic32cx_sg41_cult.X | PIC32CX1025SG41128 | PIC32CX SG41 Curiosity Ultra | TCP/IP UDP Client Server Application with LAN8740 PHY daughter board - Bare Metal
pic32cx_sg41_cult_freertos.X | PIC32CX1025SG41128 | PIC32CX SG41 Curiosity Ultra | TCP/IP UDP Client Server Application with LAN8740 PHY daughter board - FreeRTOS

## Hardware Setup

The target board for running the application is PIC32CX SG41 Curiosity Ultra.

This section provides essential hardware configuration of this target board to run TCP/IP applications.

Figure 1-24.PIC32CX SG41 Curiosity Ultra Evaluation Board

Board Setup

To set up the hardware, refer to the section Board Setup in PIC32CX SG41 Curiosity Ultra User Guide.

- Connect the micro USB cable from the computer to the DEBUG USB connector on the PIC32CX SG41 Curiosity Ultra Evaluation Board.
- Establish a connection between the router/switch with the PIC32CX SG41 Curiosity Ultra Evaluation Board through the RJ45 connector.

## Running the Application

1. Open a terminal application on the host computer (like Hyper-terminal or Tera Term).
2. Configure the terminal application for serial port connected to USB debug port of the board.
3. Set baud rate as 115200 in the terminal application.
4. Build and download the application project on the target board.
5. Verify the TCP/IP Stack initialization console messages.

GMAC - Console Start up

If 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 console. Otherwise, the default static IP address will be assigned to the board.

By entering the command netinfo and help, the response is obtained as shown above.

UDP Client Test

For UDP Client test, a UDP Server application is required to run on the host computer.

In this demonstration, we use SocketTest utility configured as UDP server.

Application commands for this demo are : setopt, getopt and sendudp.

- setopt : Set the UDP packet options like destination IP address, destination port and message to send
- getopt : Readback the current settings
- sendudp : Send the UDP packet

See the following screenshot of Console with UDP Client Commands for the test.

See the following screenshot of UDP Server (SocketTest) receiving message from UDP Client.

UDP Server Test

For UDP Server test, a UDP Client application is required to run on the host computer (SocketTest, PacketSender etc).

In this demonstration, we use SocketTest utility.

- Send a UDP packet to the IP address of the hardware board, port 9760, from UDP Client application (SocketTest) running on the computer. See the following screenshot.
- The UDP Server running on the hardware board will echo back the message it receives. See the following Console screenshot.