Skip to main content
Version: v1.1

Sample - C++ Client/Server

This repository provides a complete example of a client-server implementation in C++ designed for deployment on the AosEdge platform.

In this project, you will learn how to:

  • download and install the AOS SDK
  • set up your development environment
  • build two separate services (client and server)
  • establish communication between the services
  • create and configure services in AosCloud
  • sign and upload your services for deployment

This example serves as a solid starting point for developing and deploying custom C++-based Aos services on the AosEdge platform.

Prerequisites

  • Tools: AosCore SDK, CMake, Bash, Wget, Python and a virtual environment (venv)

Concept

  • Run a client and server service in the same SP (or across different SPs).
  • The server exposes an endpoint and hostname.
  • The client connects to the server by hostname (see source code).

Source Code

You can explore the example by checking out the source code.

Compile

Build both binaries from the client-server directory with the helper script:

./build.sh --toolchain=/path/to/environment-setup-core2-64-aos-linux

Optional argument:

./build.sh --toolchain=/path/to/environment-setup-core2-64-aos-linux --arch=<name>

Default architecture is x86.

Build output:

  • service_server/<arch>/aos_http_server
  • service_client/<arch>/aos_http_client

Configure Service Config

Before signing and uploading, review the root config.yaml file. It contains both service definitions (server and client) in the new schema format.

nano ./config.yaml

Example structure:

schemaVersion: 2
publish:
tlsKey: aos-user-sp.p12
items:
- identity:
type: service
codename: "client-server-http-server"
configuration:
hostname: my-server
images:
- archInfo:
architecture: amd64
cmd: ./aos_http_server
sourceFolder: x86
sourceFolder: service_server
- identity:
type: service
codename: "client-server-http-client"
images:
- archInfo:
architecture: amd64
cmd: ./aos_http_client
sourceFolder: x86
sourceFolder: service_client

Update values (for example hostname, versions, and signing key) as needed for your environment.

Upload services to AosCloud

From the client-server directory, run:

<host>:~/demo-services/client-server$ aos-signer go
Starting DEPLOYMENT BUNDLE SIGNING process...
Starting CONFIG VALIDATION process...
Validating config... VALID
Validating image paths... VALID
Starting BUNDLE BUILDING process...
....
Uploading... DONE
Deployment bundle successfully uploaded!

Two services should appear in the service list:

Client and server services in AosCloud list

Confirm

  1. For detailed instructions on working with logs, see Get service logs.

  2. Open the log files in a text editor and search for the message "[AOS Client Service] Response status: 200 OK".

  3. Go to Units, select your unit, and check the dashboard status.

If the message is found, the service is working correctly.