https://blog.csdn.net/dh314552189/article/details/87879016

server.cpp
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/neutrino.h>
#include <sys/dispatch.h>
#include <string.h> #define ATTACH_POINT "percent" #define VERSION "V1.2.0" int rcvid = ; struct version_message
{
int type;
char data[];
}; int main(int argc, char *argv[]) {
name_attach_t *attach;
struct version_message rmsg;
struct version_message smsg;
int rcvid; /* Create a local name (/dev/name/local/...) */
if ((attach = name_attach(NULL, ATTACH_POINT, )) == NULL) {
printf("name_attach error!\n");
return EXIT_FAILURE;
} while()
{
rcvid = MsgReceive(attach->chid, &rmsg, sizeof(rmsg), NULL);
if(rcvid > )
{
/* name_open() sends a connect message, must EOK this */
if (rmsg.type == _IO_CONNECT ) {
printf("connect received!\n");
MsgReply( rcvid, EOK, NULL, );
continue;
} /* Some other QNX IO message was received; reject it */
if (rmsg.type > _IO_BASE && rmsg.type <= _IO_MAX ) {
printf("wrong msg type received!\n");
MsgError( rcvid, ENOSYS );
continue;
} /* reply the bsp version */ if(0x1 == rmsg.type)
{
printf("version request received!\n");
printf("version request received data = %s \n",rmsg.data);
MsgReply( rcvid, EOK, NULL, );
}
}
else if( == rcvid)
{
printf("pulse msg received!\n");
}
} /* Remove the name from the space */
name_detach(attach, ); return EXIT_SUCCESS;
}
client.cpp
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <sys/mman.h> #include <sys/iofunc.h>
#include <sys/dispatch.h>
#define ATTACH_POINT "percent" struct version_message
{
int type;
char data[];
}; int main(int argc, char *argv[]) {
struct version_message smsg;
struct version_message rmsg;
int server_coid;
int rcvid; if ((server_coid = name_open(ATTACH_POINT, )) == -) {
printf("name_open error!");
return EXIT_FAILURE;
} /* We would have pre-defined data to stuff here */
smsg.type = 0x01;
strcpy(smsg.data,"ygy"); /* Do whatever work you wanted with server connection */
printf("Client sending %d \n", smsg.type);
if (MsgSend(server_coid, &smsg, sizeof(smsg), &rmsg, sizeof(rmsg)) == -) {
printf("MsgSend error!");
name_close(server_coid);
return EXIT_FAILURE;
} /* Close the connection */
name_close(server_coid);
}

cmakelist

# . Project Name

project(test.IPC)

# . Project Env (Include/Lib Path, C/CXX/LD FLAGS)

include_directories(
) link_directories(
${COMMONAPI_LIBDIR}
) # . Project Build #set(TEST_NAME "svp.test.client")
set(TEST_NAME "svp.test.server")
set(TEST_SRC_FILES # client.cpp
server.cpp
) add_executable(${TEST_NAME} ${TEST_SRC_FILES}) target_link_libraries(${TEST_NAME}
svp_basic ${upgrade_CAPI_GEN_LIB}
CommonAPI m ) # . Project Install install(TARGETS ${TEST_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

其实是有fifo也是可行的。

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/neutrino.h>
#include <sys/dispatch.h>
#include <string.h> #include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h> int main(int argc, char *argv[]) { if (access("/aaa", F_OK) == -) {
if (mkfifo("/aaa", S_IRUSR|S_IWUSR) != ) {
printf("mkfifo error!\n");
return ;
}
}
int fd = open("/aaa",O_WRONLY);
if (fd == -) {
printf("open error!\n");
return ;
}
while(){
write(fd, "ygy\n", );
sleep();
} return EXIT_SUCCESS;
}
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <sys/mman.h> #include <sys/iofunc.h>
#include <sys/dispatch.h> #include <unistd.h>
#include <fcntl.h> int main(int argc, char *argv[]) { int res = ;
int fd = open("/aaa", O_RDONLY);
char buffer[];
if (fd != -) {
printf("open ok\n");
while ((res = read(fd, buffer, )) > ) {
printf(">>>>>>>>>>>%s", buffer);
}
} }

QNX下进程间通信的更多相关文章

  1. 浅析Linux下进程间通信:共享内存

    浅析Linux下进程间通信:共享内存 共享内存允许两个或多个进程共享一给定的存储区.因为数据不需要在客户进程和服务器进程之间复制,所以它是最快的一种IPC.使用共享内存要注意的是,多个进程之间对一给定 ...

  2. WINCE下进程间通信(二)

    WINCE下进程间通信(二) 接着前面的文章<WINCE下进程间通信(一)>,现在介绍进程间通信的另一种方法. 三.管道(消息队列) WINCE并不支持类似于PC机上匿名管道.命名管道的通 ...

  3. WINCE下进程间通信(一)

    WINCE下进程间通信(一) 在WINCE开发中经常需要在不同的进程之间传递.共享数据,总结了一下,WINCE下进程间通信常用的方式有:Windows消息,共享内存,socket通信,管道,全局原子, ...

  4. Linux下进程间通信的六种机制详解

    linux下进程间通信的几种主要手段:        1.管道(Pipe)及有名管道(named pipe):管道可用于具有亲缘关系进程间的通信,有名管道克服了管道没有名字的限制,因此,除具有管道所具 ...

  5. Windows下进程间通信及数据共享

    进程是装入内存并准备执行的程序,每个进程都有私有的虚拟地址空间,由代码.数据以及它可利用的系统资源(如文件.管道等)组成. 多进程/多线程是Windows操作系统的一个基本特征.Microsoft W ...

  6. Linux下进程间通信--消息队列

    消息队列的定义遍地都是,不想移驾,请看下文: 一.定义: 消息队列提供了一种从一个进程向另一个进程发送一个数据块的方法. 每个数据块都被认 为是有一个类型,接收者进程接收的数据块可以有不同的类型值.我 ...

  7. windows下进程间通信与线程间通信

    进程间通信: 1.文件映射(Memory-Mapped Files) 文件映射(Memory-Mapped Files)能使进程把文件内容当作进程地址区间一块内存那样来对待.因此,进程不必使用文件I/ ...

  8. windows下进程间通信(转)

    摘 要 随着人们对应用程序的要求越来越高,单进程应用在许多场合已不能满足人们的要求.编写多进程/多线程程序成为现代程序设计的一个重要特点,在多进程程序设计中,进程间的通信是不可避免的.Microsof ...

  9. windows下进程间通信的(13种方法)

    转自:http://blog.csdn.NET/shiqz/article/details/5862936 摘 要 随着人们对应用程序的要求越来越高,单进程应用在许多场合已不能满足人们的要求.编写多进 ...

随机推荐

  1. 2019第十届蓝桥杯C++B组题解(赛后重写的,不确保答案正确性,仅供参考)

    先说一下这次的感受吧,我们考场比较乱,开始比赛了,还有的电脑有故障,(向这些人发出同情),第一次认真参加比赛,真正比赛的时候感觉没有那么正式,很乱,各种小问题,(例如博主就没找到题目在哪里,找到后又不 ...

  2. Django_rest_framework_组件(authentication、permission、throttle)

    认证组件 说明 from rest_framework.authentication import BaseAuthentication class TestAuthentication(BaseAu ...

  3. 为什么每次进入命令都要重新source /etc/profile 才能生效?

    https://segmentfault.com/q/1010000005981201

  4. 第28次Scrum会议(11/16)【欢迎来怼】

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,阚博文小组照片 二.开会信息 时间:2017/11/16 17:20~17:42,总计22min.地点:东北师 ...

  5. Scrum Meeting 11.03

    成员 今日任务 明日计划 用时 徐越 休息     赵庶宏 编写功能说明书,servlet代码移植 servlet代码移植 3h 薄霖 阅读上一届相关代码,思考改进方法 学习安卓界面设计数据库管理 4 ...

  6. Daily Scrumming* 2015.10.24(Day 5)

    一.总体情况总结 从今天开始,我们开始正式进入紧锣密鼓的集中开发周啦~~加油Fighting~ 开会讨论了一下各个人的细致分工,前端后端各自想成员分派任务. 继续各自领域的准备工作,同时开始进行开发. ...

  7. 四则运算《《《《SQL出题

    设计思路: 这次要用数据库存储题目,我想到的是用SQL server数据库,用dataGridView控件读取数据. 具体实现: DBCon.cs 1 using System; 2 using Sy ...

  8. 【第十周】final预发布视频

    final版本发布视频组名: 新蜂组长: 武志远组员: 宫成荣 谢孝淼 杨柳 李峤项目名称:java俄罗斯方块NEO平台:优酷地址:http://v.youku.com/v_show/id_XMTg0 ...

  9. PAT 1074 宇宙无敌加法器

    https://pintia.cn/problem-sets/994805260223102976/problems/994805263297527808 地球人习惯使用十进制数,并且默认一个数字的每 ...

  10. Majority Number III

    Given an array of integers and a number k, the majority number is the number that occursmore than 1/ ...