COVESA / vsomeip

An implementation of Scalable service-Oriented MiddlewarE over IP
Mozilla Public License 2.0
1.02k stars 651 forks source link

Communication between two devices without service discovery with static routing #544

Open jennyj1 opened 7 months ago

jennyj1 commented 7 months ago

Hello Community,

I am trying to establish the communication between two devices (device1 10.10.1.91/32 and device2 10.10.1.92/32).

I am using the static routing concept and have changed the configuration (json) file by adding unicast address under Services for both sender and receiver.

But the data is not sent.

  1. Can someone help with if any other changes needs to be made in the configuration for it to run.
  2. What does the sender and the receiver code look like without service discovery with static routing?
nachtfuchs commented 7 months ago

Hi @jennyj1 , I managed to run two applications at two different nodes with the following json files and code. I used two Xenomai systems which is basically Debian.

Note that I used IPv6. Please also note, that vsomeip3.3.8 does NOT support service discovery for IPv6, but for IPv4. A pull-request for IPv6 already exists.

Pay attention to setup your network cards correctly. They should match the unicast addresses in your json-files. Try "pinging" your two nodes, first. Then proceed with the vsomeip-applications. If possible, use Wireshark to trace the communication of your Ethernet device.

node 1:

"unicast" : "4242::1",
    "logging" :
    { 
        "level" : "trace",
        "console" : "true",
        "file" : { "enable" : "true", "path" : "/usr/cppPlayground/requestResponse2DevicesIpv6/node1_noSD.log" },
        "dlt" : "false"
    },
    "applications" : 
    [
        {
            "name" : "request-response",
            "id" : "0x1"
        }
    ],
    "services" :
    [
        {
            "service" : "0x4433",
            "instance" : "0x2211",
            "unicast" : "4242::1",
            "unreliable" : "30510"
        },
        {
            "service" : "0x1234",
            "instance" : "0x5678",
            "unicast" : "4242::2",
            "unreliable" : "30509"
        }
    ],
    "routing" : "request-response",
    "service-discovery" :
    {
        "enable" : "false",
        "multicast" : "ff12::4242",
        "port" : "30490",
        "protocol" : "udp",
        "initial_delay_min" : "10",
        "initial_delay_max" : "100",
        "repetitions_base_delay" : "200",
        "repetitions_max" : "10",
        "ttl" : "3",
        "cyclic_offer_delay" : "2000",
        "request_response_delay" : "1500"
    }
}

node2:

{
    "unicast" : "4242::2",
    "logging" :
    { 
        "level" : "trace",
        "console" : "true",
        "file" : { "enable" : "true", "path" : "/usr/requestResponseMirrored2DevicesIpv6/node2_noSD.log" },
        "dlt" : "false"
    },
    "applications" : 
    [
        {    
            "name" : "request-response-mirrored",
            "id" : "0x9"
        }
    ],
    "services" :
    [
        {
            "service" : "0x1234",
            "instance" : "0x5678",
            "unicast" : "4242::2",
            "unreliable" : "30509"
        },
        {
            "service" : "0x4433",
            "instance" : "0x2211",
            "unicast": "4242::1",
            "unreliable" : "30510"
        }
    ],
    "routing" : "request-response-mirrored",
    "service-discovery" :
    {
        "enable" : "false",
        "multicast" : "ff12::4242",
        "port" : "30490",
        "protocol" : "udp",
        "initial_delay_min" : "10",
        "initial_delay_max" : "100",
        "repetitions_base_delay" : "200",
        "repetitions_max" : "3",
        "ttl" : "3",
        "cyclic_offer_delay" : "2000",
        "request_response_delay" : "1500"
    }
}

the cpp-files:

request-response.cpp:

// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// Trying to add a response to a client
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
#include <csignal>
#endif
#include <chrono>
#include <condition_variable>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <thread>

#include <vsomeip/vsomeip.hpp>

#include "sample-ids.hpp"

class serverClient {
public:
    serverClient(bool _use_tcp, bool _be_quiet, uint32_t _cycle)
        : app_(vsomeip::runtime::get()->create_application()),
          request_(vsomeip::runtime::get()->create_request(_use_tcp)),
          use_tcp_(_use_tcp),
          be_quiet_(_be_quiet),
          cycle_(_cycle),
          running_(true),
          blocked_(false),
          is_available_(false),
          sender_(std::bind(&serverClient::run, this)), 

          // reponse content
          is_registered_(false)
          {
    }

    bool init() {
        std::lock_guard<std::mutex> its_lock(mutex_);

        if (!app_->init()) {
            std::cerr << "Couldn't initialize application" << std::endl;
            return false;
        }

        std::cout << "Server & Client settings [protocol="
                  << (use_tcp_ ? "TCP" : "UDP")
                  << ":quiet="
                  << (be_quiet_ ? "true" : "false")
                  << ":cycle="
                  << cycle_
                  << "]"
                  << std::endl;

        app_->register_state_handler(
                std::bind(
                    &serverClient::on_state,
                    this,
                    std::placeholders::_1));

        app_->register_message_handler(
                SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID,
                std::bind(&serverClient::on_message,
                          this,
                          std::placeholders::_1));

        app_->register_message_handler(
                SAMPLE_SERVICE2_ID, SAMPLE_INSTANCE2_ID, SAMPLE_METHOD2_ID,
                std::bind(&serverClient::on_message2, this,
                        std::placeholders::_1));

        request_->set_service(SAMPLE_SERVICE_ID);
        request_->set_instance(SAMPLE_INSTANCE_ID);
        request_->set_method(SAMPLE_METHOD_ID);

        std::shared_ptr< vsomeip::payload > its_payload = vsomeip::runtime::get()->create_payload();
        std::vector< vsomeip::byte_t > its_payload_data;
        for (std::size_t i = 0xc0; i < 0xc0 + 10; ++i)
            its_payload_data.push_back(vsomeip::byte_t(i % 256));
        its_payload->set_data(its_payload_data);
        request_->set_payload(its_payload);

        app_->register_availability_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID,
                std::bind(&serverClient::on_availability,
                          this,
                          std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

        return true;
    }

    void start() {
        app_->start();
    }

#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
    /*
     * Handle signal to shutdown
     */
    void stop() {
        running_ = false;
        blocked_ = true;
        app_->clear_all_handler();
        stop_offer();
        app_->release_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
        condition_.notify_one();
        sender_.join();
        app_->stop();
    }
#endif

    void offer() {
        app_->offer_service(SAMPLE_SERVICE2_ID, SAMPLE_INSTANCE2_ID);
    }

    void stop_offer() {
        app_->stop_offer_service(SAMPLE_SERVICE2_ID, SAMPLE_INSTANCE2_ID);
    }

    void on_state(vsomeip::state_type_e _state) {
        if (_state == vsomeip::state_type_e::ST_REGISTERED) {
            app_->request_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);

            if (!is_registered_) {
                is_registered_ = true;
                blocked_ = true;
                condition_.notify_one();
            }
        } else {
            is_registered_ = false;
        }
    }

    void on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
        std::cout << "Service ["
                << std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
                << "] is "
                << (_is_available ? "available." : "NOT available.")
                << std::endl;

        if (SAMPLE_SERVICE_ID == _service && SAMPLE_INSTANCE_ID == _instance) {
            if (is_available_  && !_is_available) {
                is_available_ = false;
            } else if (_is_available && !is_available_) {
                is_available_ = true;
                send();
            }
        }
    }

    void on_message(const std::shared_ptr< vsomeip::message > &_response) {
        // Get payload
        std::shared_ptr<vsomeip::payload> its_payload = _response->get_payload();
        vsomeip::length_t l = its_payload->get_length();

        std::stringstream ss;
        for (vsomeip::length_t i=0; i<l; i++) {
            ss << std::setw(2) << std::setfill('0') << std::hex
                << (int)*(its_payload->get_data()+i) << " ";
        }

        std::cout << "\033[32mReceived a response from Service ["
                << std::setfill('0') << std::hex
                << std::setw(4) << _response->get_service()
                << "."
                << std::setw(4) << _response->get_instance()
                << "] to Client/Session ["
                << std::setw(4) << _response->get_client()
                << "/"
                << std::setw(4) << _response->get_session()
                << "]:\033[0m"
                << ss.str() << std::endl;
        if (is_available_)
            send();
    }

    // @brief Trying to implement a second service with request handling
    void on_message2(const std::shared_ptr<vsomeip::message> &_request) {
        // Get payload
        std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
        vsomeip::length_t l = its_payload->get_length();

        std::stringstream ss;
        for (vsomeip::length_t i=0; i<l; i++) {
        ss << std::setw(2) << std::setfill('0') << std::hex
            << (int)*(its_payload->get_data()+i) << " ";
        }

        std::cout << "\033[32mSERVICE 2: Received a message with Client/Session ["
          << std::setfill('0') << std::hex
          << std::setw(4) << _request->get_client() << "/"
          << std::setw(4) << _request->get_session() << "]:\033[0m"
          << ss.str() << std::endl;

        std::shared_ptr<vsomeip::message> its_response
            = vsomeip::runtime::get()->create_response(_request);

        std::shared_ptr<vsomeip::payload> response_payload
            = vsomeip::runtime::get()->create_payload();
        std::vector<vsomeip::byte_t> its_payload_data;
        for (std::size_t i = 0; i < l; ++i)
            its_payload_data.push_back(vsomeip::byte_t(0x10 + (int)*(its_payload->get_data()+i)));
        response_payload->set_data(its_payload_data);
        its_response->set_payload(response_payload);

        app_->send(its_response);

        ss.str(std::string());
        ss.clear();
        for (vsomeip::length_t i=0; i<l; i++) {
            ss << std::setw(2) << std::setfill('0') << std::hex
            << (int)*(response_payload->get_data()+i) << " ";
        }
        std::cout << "\033[34mSERVICE 2: Sent a response to Client/Session ["
          << std::setfill('0') << std::hex
          << std::setw(4) << _request->get_client() << "/"
          << std::setw(4) << _request->get_session() << "]:\033[0m"
          << ss.str() << std::endl;
    }

    void send() {
        if (!be_quiet_)
        {
            std::lock_guard< std::mutex > its_lock(mutex_);
            blocked_ = true;
            condition_.notify_one();
        }
    }

    void run() {
        bool is_offer(true);
        while (running_) {
            {
                std::unique_lock<std::mutex> its_lock(mutex_);
                while (!blocked_) condition_.wait(its_lock);
                if (is_offer)
                    offer();
                else
                    stop_offer();

                if (is_available_) {
                    app_->send(request_);
                    // Get payload
                    std::shared_ptr<vsomeip::payload> its_payload = request_->get_payload();
                    vsomeip::length_t l = its_payload->get_length();

                    std::stringstream ss;
                    for (vsomeip::length_t i=0; i<l; i++) {
                        ss << std::setw(2) << std::setfill('0') << std::hex
                            << (int)*(its_payload->get_data()+i) << " ";
                    }

                    std::cout << "\033[34mClient/Session ["
                            << std::setfill('0') << std::hex
                            << std::setw(4) << request_->get_client()
                            << "/"
                            << std::setw(4) << request_->get_session()
                            << "] sent a request to Service ["
                            << std::setw(4) << request_->get_service()
                            << "."
                            << std::setw(4) << request_->get_instance()
                            << "]:\033[0m"
                            << ss.str() << std::endl;
                    blocked_ = false;
                }
            }
            std::this_thread::sleep_for(std::chrono::milliseconds(cycle_));
        }
    }

private:
    std::shared_ptr< vsomeip::application > app_;
    std::shared_ptr< vsomeip::message > request_;
    bool use_tcp_;
    bool be_quiet_;
    uint32_t cycle_;
    std::mutex mutex_;
    std::condition_variable condition_;
    bool running_;
    bool blocked_;
    bool is_available_;

    std::thread sender_;

    // response content
    bool is_registered_;
};

#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
    serverClient *its_sample_ptr(nullptr);
    void handle_signal(int _signal) {
        if (its_sample_ptr != nullptr &&
                (_signal == SIGINT || _signal == SIGTERM))
            its_sample_ptr->stop();
    }
#endif

int main(int argc, char **argv) {
    bool use_tcp = false;
    bool be_quiet = false;
    uint32_t cycle = 1000; // Default: 1s

    std::string tcp_enable("--tcp");
    std::string udp_enable("--udp");
    std::string quiet_enable("--quiet");
    std::string cycle_arg("--cycle");

    int i = 1;
    while (i < argc) {
        if (tcp_enable == argv[i]) {
            use_tcp = true;
        } else if (udp_enable == argv[i]) {
            use_tcp = false;
        } else if (quiet_enable == argv[i]) {
            be_quiet = true;
        } else if (cycle_arg == argv[i] && i+1 < argc) {
            i++;
            std::stringstream converter;
            converter << argv[i];
            converter >> cycle;
        }
        i++;
    }

    serverClient its_sample(use_tcp, be_quiet, cycle);
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
    its_sample_ptr = &its_sample;
    signal(SIGINT, handle_signal);
    signal(SIGTERM, handle_signal);
#endif
    if (its_sample.init()) {
        its_sample.start();
        return 0;
    } else {
        return 1;
    }
}

request-response-mirrored.cpp

// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// Trying to add a response to a client
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
#include <csignal>
#endif
#include <chrono>
#include <condition_variable>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <thread>

#include <vsomeip/vsomeip.hpp>

#include "sample-ids.hpp"

class serverClient {
public:
    serverClient(bool _use_tcp, bool _be_quiet, uint32_t _cycle)
        : app_(vsomeip::runtime::get()->create_application()),
          request_(vsomeip::runtime::get()->create_request(_use_tcp)),
          use_tcp_(_use_tcp),
          be_quiet_(_be_quiet),
          cycle_(_cycle),
          running_(true),
          blocked_(false),
          is_available_(false),
          sender_(std::bind(&serverClient::run, this)), 

          // reponse content
          is_registered_(false)
          {
    }

    bool init() {
        std::lock_guard<std::mutex> its_lock(mutex_);

        if (!app_->init()) {
            std::cerr << "Couldn't initialize application" << std::endl;
            return false;
        }

        std::cout << "Server & Client settings [protocol="
                  << (use_tcp_ ? "TCP" : "UDP")
                  << ":quiet="
                  << (be_quiet_ ? "true" : "false")
                  << ":cycle="
                  << cycle_
                  << "]"
                  << std::endl;

        app_->register_state_handler(
                std::bind(
                    &serverClient::on_state,
                    this,
                    std::placeholders::_1));

        app_->register_message_handler(
                SAMPLE_SERVICE2_ID, SAMPLE_INSTANCE2_ID, SAMPLE_METHOD2_ID,
                std::bind(&serverClient::on_message,
                          this,
                          std::placeholders::_1));

        app_->register_message_handler(
                SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID,
                std::bind(&serverClient::on_message2, this,
                        std::placeholders::_1));

        request_->set_service(SAMPLE_SERVICE2_ID);
        request_->set_instance(SAMPLE_INSTANCE2_ID);
        request_->set_method(SAMPLE_METHOD2_ID);

        std::shared_ptr< vsomeip::payload > its_payload = vsomeip::runtime::get()->create_payload();
        std::vector< vsomeip::byte_t > its_payload_data;
        for (std::size_t i = 0xa0; i < 0xa0+10; ++i)
            its_payload_data.push_back(vsomeip::byte_t(i % 256));
        its_payload->set_data(its_payload_data);
        request_->set_payload(its_payload);

        app_->register_availability_handler(SAMPLE_SERVICE2_ID, SAMPLE_INSTANCE2_ID,
                std::bind(&serverClient::on_availability,
                          this,
                          std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

        return true;
    }

    void start() {
        app_->start();
    }

#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
    /*
     * Handle signal to shutdown
     */
    void stop() {
        running_ = false;
        blocked_ = true;
        app_->clear_all_handler();
        stop_offer();
        app_->release_service(SAMPLE_SERVICE2_ID, SAMPLE_INSTANCE2_ID);
        condition_.notify_one();
        sender_.join();
        app_->stop();
    }
#endif

    void offer() {
        app_->offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
    }

    void stop_offer() {
        app_->stop_offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
    }

    void on_state(vsomeip::state_type_e _state) {
        if (_state == vsomeip::state_type_e::ST_REGISTERED) {
            app_->request_service(SAMPLE_SERVICE2_ID, SAMPLE_INSTANCE2_ID);

            if (!is_registered_) {
                is_registered_ = true;
                blocked_ = true;
                condition_.notify_one();
            }
        } else {
            is_registered_ = false;
        }
    }

    void on_availability(vsomeip::service_t _service, vsomeip::instance_t _instance, bool _is_available) {
        std::cout << "Service ["
                << std::setw(4) << std::setfill('0') << std::hex << _service << "." << _instance
                << "] is "
                << (_is_available ? "available." : "NOT available.")
                << std::endl;

        if (SAMPLE_SERVICE2_ID == _service && SAMPLE_INSTANCE2_ID == _instance) {
            if (is_available_  && !_is_available) {
                is_available_ = false;
            } else if (_is_available && !is_available_) {
                is_available_ = true;
                send();
            }
        }
    }

    void on_message(const std::shared_ptr< vsomeip::message > &_response) {
        // Get payload
        std::shared_ptr<vsomeip::payload> its_payload = _response->get_payload();
        vsomeip::length_t l = its_payload->get_length();

        std::stringstream ss;
        for (vsomeip::length_t i=0; i<l; i++) {
            ss << std::setw(2) << std::setfill('0') << std::hex
                << (int)*(its_payload->get_data()+i) << " ";
        }

        std::cout << "\033[32mReceived a response from Service ["
                << std::setfill('0') << std::hex
                << std::setw(4) << _response->get_service()
                << "."
                << std::setw(4) << _response->get_instance()
                << "] to Client/Session ["
                << std::setw(4) << _response->get_client()
                << "/"
                << std::setw(4) << _response->get_session()
                << "]:\033[0m"
                << ss.str() << std::endl;
        if (is_available_)
            send();
    }

    // @brief Trying to implement a second service with request handling
    void on_message2(const std::shared_ptr<vsomeip::message> &_request) {
        // Get payload
        std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
        vsomeip::length_t l = its_payload->get_length();

        std::stringstream ss;
        for (vsomeip::length_t i=0; i<l; i++) {
        ss << std::setw(2) << std::setfill('0') << std::hex
            << (int)*(its_payload->get_data()+i) << " ";
        }

        std::cout << "\033[32mSERVICE 2: Received a message with Client/Session ["
          << std::setfill('0') << std::hex
          << std::setw(4) << _request->get_client() << "/"
          << std::setw(4) << _request->get_session() << "]:\033[0m"
          << ss.str() << std::endl;

        std::shared_ptr<vsomeip::message> its_response
            = vsomeip::runtime::get()->create_response(_request);

        std::shared_ptr<vsomeip::payload> response_payload
            = vsomeip::runtime::get()->create_payload();
        std::vector<vsomeip::byte_t> its_payload_data;
        for (std::size_t i = 0; i < l; ++i)
            its_payload_data.push_back(vsomeip::byte_t( 0x10 + (int)*(its_payload->get_data()+i) ));
        response_payload->set_data(its_payload_data);
        its_response->set_payload(response_payload);

        app_->send(its_response);
        ss.str(std::string());
        ss.clear();
        for (vsomeip::length_t i=0; i<l; i++) {
            ss << std::setw(2) << std::setfill('0') << std::hex
            << (int)*(response_payload->get_data()+i) << " ";
        }
        std::cout << "\033[34mSERVICE 2: Sent a response to Client/Session ["
          << std::setfill('0') << std::hex
          << std::setw(4) << _request->get_client() << "/"
          << std::setw(4) << _request->get_session() << "]:\033[0m"
          << ss.str() << std::endl;
    }

    void send() {
        if (!be_quiet_)
        {
            std::lock_guard< std::mutex > its_lock(mutex_);
            blocked_ = true;
            condition_.notify_one();
        }
    }

    void run() {
        bool is_offer(true);
        while (running_) {
            {
                std::unique_lock<std::mutex> its_lock(mutex_);
                while (!blocked_) condition_.wait(its_lock);
                if (is_offer)
                    offer();
                else
                    stop_offer();

                if (is_available_) {
                    app_->send(request_);
                    // Get payload
                    std::shared_ptr<vsomeip::payload> its_payload = request_->get_payload();
                    vsomeip::length_t l = its_payload->get_length();

                    std::stringstream ss;
                    for (vsomeip::length_t i=0; i<l; i++) {
                        ss << std::setw(2) << std::setfill('0') << std::hex
                            << (int)*(its_payload->get_data()+i) << " ";
                    }

                    std::cout << "\033[34mClient/Session ["
                            << std::setfill('0') << std::hex
                            << std::setw(4) << request_->get_client()
                            << "/"
                            << std::setw(4) << request_->get_session()
                            << "] sent a request to Service ["
                            << std::setw(4) << request_->get_service()
                            << "."
                            << std::setw(4) << request_->get_instance()
                            << "]:\033[0m"
                            << ss.str() << std::endl;
                    blocked_ = false;
                }
            }
            std::this_thread::sleep_for(std::chrono::milliseconds(cycle_));
        }
    }

private:
    std::shared_ptr< vsomeip::application > app_;
    std::shared_ptr< vsomeip::message > request_;
    bool use_tcp_;
    bool be_quiet_;
    uint32_t cycle_;
    std::mutex mutex_;
    std::condition_variable condition_;
    bool running_;
    bool blocked_;
    bool is_available_;

    std::thread sender_;

    // response content
    bool is_registered_;
};

#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
    serverClient *its_sample_ptr(nullptr);
    void handle_signal(int _signal) {
        if (its_sample_ptr != nullptr &&
                (_signal == SIGINT || _signal == SIGTERM))
            its_sample_ptr->stop();
    }
#endif

int main(int argc, char **argv) {
    bool use_tcp = false;
    bool be_quiet = false;
    uint32_t cycle = 1000; // Default: 1s

    std::string tcp_enable("--tcp");
    std::string udp_enable("--udp");
    std::string quiet_enable("--quiet");
    std::string cycle_arg("--cycle");

    int i = 1;
    while (i < argc) {
        if (tcp_enable == argv[i]) {
            use_tcp = true;
        } else if (udp_enable == argv[i]) {
            use_tcp = false;
        } else if (quiet_enable == argv[i]) {
            be_quiet = true;
        } else if (cycle_arg == argv[i] && i+1 < argc) {
            i++;
            std::stringstream converter;
            converter << argv[i];
            converter >> cycle;
        }
        i++;
    }

    serverClient its_sample(use_tcp, be_quiet, cycle);
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
    its_sample_ptr = &its_sample;
    signal(SIGINT, handle_signal);
    signal(SIGTERM, handle_signal);
#endif
    if (its_sample.init()) {
        its_sample.start();
        return 0;
    } else {
        return 1;
    }
}

sample-ids.hpp:

// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef VSOMEIP_EXAMPLES_SAMPLE_IDS_HPP
#define VSOMEIP_EXAMPLES_SAMPLE_IDS_HPP

#define SAMPLE_SERVICE_ID       0x1234
#define SAMPLE_INSTANCE_ID      0x5678
#define SAMPLE_METHOD_ID        0x0421

// for second service
#define SAMPLE_SERVICE2_ID       0x4433
#define SAMPLE_INSTANCE2_ID      0x2211
#define SAMPLE_METHOD2_ID        0x0abc

#define SAMPLE_EVENT_ID         0x8778
#define SAMPLE_GET_METHOD_ID    0x0001
#define SAMPLE_SET_METHOD_ID    0x0002

#define SAMPLE_EVENTGROUP_ID    0x4465

#define OTHER_SAMPLE_SERVICE_ID 0x0248
#define OTHER_SAMPLE_INSTANCE_ID 0x5422
#define OTHER_SAMPLE_METHOD_ID  0x1421

#endif // VSOMEIP_EXAMPLES_SAMPLE_IDS_HPP

makefile


request-response: request-response.cpp
    @echo "Creating request-response"
    g++ -o $(BUILDNAME) request-response.cpp -std=c++14 -lvsomeip3 -pthread

clean:
    @echo "Removing executable"
    rm -f $(BUILDNAME)
jennyj1 commented 7 months ago

Hi @nachtfuchs,

Thank you for your quick and detailed response.

I tried running the code by replacing iPv6 addresses with iPv4 addresses since that is my application. But communication is not established. Do we need to make any other changes in order to run the code with iPv4 addressing.

Please Note: My aim is to have a client server communication without service discovery between two devices.

nachtfuchs commented 7 months ago

Did you setup your network connections correctly? Can you ping between them? What do you see in Wireshark? Do you see outgoing messages? And when you start your application, do you see that your application is loading the correct ethernet device? Usually it tells which IPs it is using and which device it uses. This must be aligned with your network settings.

jennyj1 commented 7 months ago

Dear @nachtfuchs ,

Thanks a lot for the code and the support. I am able to run the code sent by you. But since there is no part configured as client that is why we are not able to receive any data and hence check whether our network is communicating or not and if data is being sent or not. In my case I am not able to see any data packets in wireshark also.

It would have been great if you could help with modifying the code to configure some client/receiver to capture the payload and print it. I am not able to do it.

nachtfuchs commented 7 months ago

If you check my code, there are two specific files. One is "request-response.cpp". The other is "request-response-mirrored.cpp". They do exactly what you are trying to achieve. One sends data, the other receives data. And vice versa, because there are two services. So the solution is - in my eyes - right in front of you.

Gokul123-dev commented 6 months ago

Hi @nachtfuchs , I have checked the above code , in "request-response.cpp" and "request-response-mirrored.cpp" both are sending data and receiving data on both ends . It would have been great if you provide the code for one client and one server where "request-response-mirrored.cpp" acts as server sending data to client "request-response.cpp" with out service discovery . IMP : Without Service Discovery! from one server to one client.

nachtfuchs commented 6 months ago

@Gokul123-dev The code already deactivated service discovery. If you want further freelance work, I can do it for you. It is USD 500 per hour ;-). Let me know if you are interested, I will send you my payment details.

maramharsha99 commented 5 months ago

hello @jennyj1 Can you help me with a similar problem ? I was not able to figure out the issue. I am using hello_world codes to build communication between two devices.