VSOMEIP双机通信
环境:两台虚拟机配置的Ubuntu20.04 (默认部署好vsomeip并且编译过)
- 编译helloworld程序
按照上图helloworld 文件里的readme步骤来 - 配置hello world服务端配置文件
{
"unicast":"192.168.52.129",
"logging":
{
"level":"debug",
"console":"true",
"file" : { "enable" : "false", "path" : "/tmp/vsomeip.log" },
"dlt" : "false"
},
"applications":
[
{
"name":"hello_world_service",
"id":"0x4444"
},
],
"services":
[
{
"service":"0x1111",
"instance":"0x2222",
"unreliable":"30509"
}
],
"routing":"hello_world_service",
"service-discovery":
{
"enable":"false",
"enable" : "true",
"multicast" : "224.224.224.245",
"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"
}
}
- 配置端口并且运行服务端
route add -host 224.224.224.245 dev <interface>
运行服务端指令:
先把helloworld-local.json文件复制到build文件下。
如图:
再运行以下指令:
env VSOMEIP_CONFIGURATION=./helloworld-local.json VSOMEIP_APPLICATION_NAME=hello_world_service
./hello_world_service
- 将make出来的客户端可执行文件复制到另一台虚拟机上,再配置配置文件如图:
配置文件内容如图:
{
"unicast":"192.168.52.128",
"logging":
{
"level":"debug",
"console":"true",
"file" : { "enable" : "false", "path" : "/tmp/vsomeip.log" },
"dlt" : "false"
},
"applications":
[
{
"name":"hello_world_client",
"id":"0x5555"
}
],
"routing":"hello_world_client",
"service-discovery":
{
"enable" : "true",
"multicast" : "224.224.224.245",
"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"
}
}
然后再进行如下指令
export LD_LIBRARY_PATH=/home/zyf/vsomeip-master/build
route add -host 224.224.224.245 dev <interface>
env VSOMEIP_CONFIGURATION=./helloworld-local.json VSOMEIP_APPLICATION_NAME=hello_world_client
./hello_world_client
终端显示如图:
代码都是vsomeip/examples/hello_world下的代码