[VPP] vpp_com使用

简介: [VPP] vpp_com使用

vppcom_server.c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <vcl/vppcom.h>
// vppcom
// ./vppcom_server 192.168.0.29 8888
int main(int argc, char *argv[]) {
  int rv = 0;
  printf("vppcom server: %d\n", argc);
  if (argc < 3) return -1;
  struct sockaddr_in servaddr;
  memset(&servaddr, 0, sizeof(struct sockaddr_in ));
  servaddr.sin_family = AF_INET;
  //servaddr.sin_addr
  inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
  servaddr.sin_port = atoi(argv[2]);
  rv = vppcom_app_create("vppcom_server\n");
  if (rv) {
    printf("vppcom_app_create\n");
    return -1;
  }
  int listenfd = vppcom_session_create(VPPCOM_PROTO_TCP, 0);
  if (listenfd < 0) {
    return -1;
  }
  printf("vppcom_session_create: %s, %s\n", argv[1], argv[2]);
  vppcom_endpt_t endpt;
  memset(&endpt, 0, sizeof(endpt));
  endpt.is_ip4 = 1;
  endpt.ip = (uint8_t*)&servaddr.sin_addr; 
  endpt.port = htons(servaddr.sin_port); //
  rv = vppcom_session_bind(listenfd, &endpt);
  if (rv < 0) {
    printf("vppcom_session_bind failed\n");
    return -1;
  }
  rv = vppcom_session_listen(listenfd, 10);
  if (rv < 0) {
    printf("vppcom_session_listen failed\n");
    return -1;
  }
  vppcom_endpt_t clientpt;
  int clientfd = vppcom_session_accept(listenfd, &clientpt, 0);
  if (clientfd < 0) {
    printf("vppcom_session_accept failed\n");
    return -1;
  }
  char buffer[1024];
  memset(buffer, 0,sizeof(buffer));
  rv = vppcom_session_read(clientfd, buffer, sizeof(buffer));
  if (rv < 0) {
    printf("vppcom_session_accept failed\n");
    return -1;
  }
  printf("Received from client length: %d , %s\n", rv, buffer);
  rv = vppcom_session_write(clientfd, buffer, rv);
  vppcom_session_close(clientfd);
  vppcom_app_destroy();
  return 0;
}

vppcom_client.c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <vcl/vppcom.h>
// vppcom
// ./vppcom_client 192.168.0.29 8888
int main(int argc, char *argv[]) {
  int rv = 0;
  printf("vppcom server: %d\n", argc);
  if (argc < 3) return -1;
  struct sockaddr_in servaddr;
  memset(&servaddr, 0, sizeof(struct sockaddr_in ));
  servaddr.sin_family = AF_INET;
  //servaddr.sin_addr
  inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
  servaddr.sin_port = atoi(argv[2]);
  rv = vppcom_app_create("vppcom_server\n");
  if (rv) {
    printf("vppcom_app_create\n");
    return -1;
  }
  int connfd = vppcom_session_create(VPPCOM_PROTO_TCP, 0);
  if (connfd < 0) {
    return -1;
  }
  printf("vppcom_session_create: %s, %s\n", argv[1], argv[2]);
  vppcom_endpt_t endpt;
  memset(&endpt, 0, sizeof(endpt));
  endpt.is_ip4 = 1;
  endpt.ip = (uint8_t*)&servaddr.sin_addr; 
  endpt.port = htons(servaddr.sin_port); //
  rv = vppcom_session_connect(connfd, &endpt);
  if (rv < 0) {
    printf("vppcom_session_bind failed\n");
    return -1;
  }
  char *str = "vppcomclient\n";
  rv = vppcom_session_write(connfd, str, strlen(str));
  if (rv < 0) {
    printf("vppcom_session_accept failed\n");
    return -1;
  }
  char buffer[1024] = {0};
  rv = vppcom_session_read(connfd, buffer, sizeof(buffer));
  if (rv < 0) {
    printf("vppcom_session_accept failed\n");
    return -1;
  }
  printf("Received from client length: %d , %s\n", rv, buffer);
  vppcom_session_close(connfd);
  vppcom_app_destroy();
  return 0;
}


相关文章
|
存储 前端开发 Linux
DPDK-mempool(1)
DPDK-mempool(1)
376 0
|
运维 安全 Cloud Native
国产Linux:OpenEuler能否完美替代CentOS系统?
本文讨论了OpenEuler系统作为替代CentOS的一个有潜力的选择。OpenEuler系统是一种基于开源技术和社区支持的Linux发行版,具有许多优势,如安全性、高度可定制性、强大的社区支持、容器和云原生生态系统集成以及持续更新等。与CentOS相比,OpenEuler系统提供更多的灵活性和可定制性,适用于各种用途和工作负载。但在选择OpenEuler系统时,用户需要进行仔细评估并考虑其适用性和可行性。
|
存储 测试技术 网络安全
冲破内核限制:使用DPDK提高网络应用程序的性能(下)
冲破内核限制:使用DPDK提高网络应用程序的性能
|
监控 数据可视化 搜索推荐
现代教育管理中的看板应用:任务可视化的强大力量
化解教学压力,赋予课堂活力,试试看板工具
311 7
现代教育管理中的看板应用:任务可视化的强大力量
|
负载均衡 前端开发 Java
OpenFeign:Spring Cloud声明式服务调用组件
该文本是关于OpenFeign在Spring Cloud中的使用的问答总结。涉及的问题包括:OpenFeign是什么,Feign与OpenFeign的区别,如何使用OpenFeign进行远程服务调用,OpenFeign的超时控制以及日志增强。OpenFeign被描述为Spring官方的声明式服务调用和负载均衡组件,它支持使用注解进行接口定义和服务调用,如@FeignClient和@EnableFeignClients。OpenFeign与Feign的主要区别在于OpenFeign支持Spring MVC注解。超时控制通过Ribbon进行设置,默认超时时间为1秒。
195 1
|
编译器 Linux 网络性能优化
VPP使用DPDK纳管主机网卡
VPP使用DPDK纳管主机网卡
|
Kubernetes 网络协议 Linux
Cilium 系列 -5-Cilium 替换 KubeProxy
Cilium 系列 -5-Cilium 替换 KubeProxy
|
Ubuntu Linux 网络性能优化
VPP安装
VPP安装
739 0
|
Web App开发 网络协议 安全
FastGithub:github加速神器,解决github打不开、用户头像无法加载、releases无法上传下载、git-clone、git-pull、git-push失败等问题。
FastGithub:github加速神器,解决github打不开、用户头像无法加载、releases无法上传下载、git-clone、git-pull、git-push失败等问题。
FastGithub:github加速神器,解决github打不开、用户头像无法加载、releases无法上传下载、git-clone、git-pull、git-push失败等问题。

热门文章

最新文章