7.3.1. Binary: Mirror

Under this section you will find a simple example of a client/server application using the eCAL ClientServer API. You should be already familiar with the base handling of eCAL from the Publisher/Subscriber samples, so this we will not be covered in detail any more.

7.3.1.1. Mirror Server

A service server is an eCAL instance that is matched to service client instances by their name. It can offer multiple methods, which a connected service client can call. We will set up a simple server that provides two methods: “echo” and “mirror”.

The main process is:

  • Intialize eCAL

  • Create a Service Server

  • For each method, add meta information about that method (such as method name, and types of the request and response) and a callback function to be invoked, when a client calls that method

  • Keep the program running while the service is supposed to be executed

|fa-folder-open|
├─ |fa-folder-open| C++
│  └─ |fa-file-alt| mirror_server.cpp
│
├─ |fa-folder-open| C
│  └─ |fa-file-alt| mirror_server.c
│
├─ |fa-folder-open| C#
│  └─ |fa-file-alt| mirror_server.cs
│
├─ |fa-folder-open| Python
│  └─ |fa-file-alt| mirror_server.py
│
└─ |fa-folder-open| Python (legacy)
   └─ |fa-file-alt| mirror_server.py

7.3.1.2. Mirror Client

The client will have some more logic to take care of, as its possible that multiple servers are running with the same service name.

  • Initialize eCAL

  • Create a service client with the service name and (optionally) register the functions it can call (in this case “echo” and “mirror”)

  • Waiting for a server to be available (this is optional and depends on how you want to design your application)

  • Retrieve all client instances. You can also call it directly on the service client, but if you iterate through all client instances, you are more flexible and could filter out instances you don’t want to call.

  • Then we call the methodnames with two different calls: with callback (non blocking) and with response (blocking)

  • Handle the received data (or error status)

As a little extra we also added a little bit more eCAL state handling as in the previous examples.

|fa-folder-open|
├─ |fa-folder-open| C++
│  └─ |fa-file-alt| mirror_client.cpp
│
├─ |fa-folder-open| C
│  └─ |fa-file-alt| mirror_client.c
│
├─ |fa-folder-open| C#
│  └─ |fa-file-alt| mirror_client.cs
│
├─ |fa-folder-open| Python
│  └─ |fa-file-alt| mirror_client.py
│
└─ |fa-folder-open| Python (legacy)
   └─ |fa-file-alt| mirror_client.py