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. 获400 万美元 A 轮融资,ShipBob 想帮助小微企业享受Amazon Prime 级配送服务 2016-06-18

    Weiss认为,无论零售市场的发展走向如何波动,ShipBob公司都能够获得坚实的成长表现. 在线销售实体商品的小型企业当然希望利用种种方式取悦客户,但面对着Amazon Prime迅如闪电且价格实惠 ...

  2. Array.Copy 数据是克隆吗?

    偶然看到 Array.Copy 方法的时候,想到,它是否是克隆,又是否是深克隆. 做了一个测试 public class abc { public string hello; } [TestMetho ...

  3. Mysql DataPacketTooBigException异常处理

    在本地上运行好好,然后发布到服务器上去, 总是报错,后来查了一下日志,得到了如下的错误日志: [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] Pa ...

  4. redis使用哈希槽实现集群

    Redis Cluster集群 一.redis-cluster设计 Redis集群搭建的方式有多种,例如使用zookeeper等,但从redis 3.0之后版本支持redis-cluster集群,Re ...

  5. webpack入门指南-step04

    一.建立项目 建一个文件夹,然后新建一个package.json的文件在项目根目录下 如果你使用git管理你的这个项目的话,建议你新建一个.gitignore文件,不要让git提交一些node依赖的模 ...

  6. Daily Scrum5 11.7

    今日任务: 姓名 任务 时长 徐钧鸿 学习了java连接sqlserver的方法并且实现了连接池 2h 张艺 继续完成和用户管理有关的类的移植(Register.Success.Validate等) ...

  7. 20162314 《Program Design & Data Structures》Learning Summary Of The First Week

    20162314 2017-2018-1 <Program Design & Data Structures>Learning Summary Of The First Week ...

  8. FileInputStream 读取文件数据的输入字节流

    package com.inputstream; /* File类: 用于描述一个文件或者文件夹的. 通过File对象我们可以读取文件或者文件夹的属性数据,如果我们需要读取文件的内容数据,那么我们需要 ...

  9. 新的Calculator的规范作业

    附加作业题目 第三次作业 mygithub:sonnypp 这是开学来第一次写随笔,这一次的作业是对上一次作业的修改,对于上一次作业,在学长老师的帮助下,我重新修改了下代码,将.h文件分成了一个Sca ...

  10. ubuntu16.04+matlab r2015b VideoReader报错

    读取.mp4出错 需要安装gstreamer0.10-ffmpeg ` sudo add-apt-repository ppa:mc3man/gstffmpeg-keep sudo apt-get u ...