⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svmsg_c.cpp

📁 在Linux使用systemV测试消息
💻 CPP
字号:
#include <stdio.h>#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>

#include "./svmsg.h"#include "./svmsg.cpp"int main(){
	int iMesgID;
	int ret,flag;
	int i,iBytes;
	struct Mesg_Struct strupMesg_s,strupMesg_c;

	printf("==== Ren Message Queue Client ====\n");
	flag=0;
	iMesgID=Mesg_get(MSQ_NET_KEY,IPC_CREAT);	if(iMesgID==-1){
		printf(".... Get message queue Error:%s! ....\n",strerror(errno));		return -1;
	}
	memset(&strupMesg_s,0,sizeof(Mesg_Struct));	memset(&strupMesg_c,0,sizeof(Mesg_Struct));	strupMesg_s.iMesgType=MSQ_NET_TYPE;	strupMesg_c.iMesgType=MSQ_METER_TYPE;
	strupMesg_c.iMesgLen=20;	for(i=0;i<20;i++)		strupMesg_c.cMesgData[i]=i+20;
	while(1){
		if(flag!=0x5a){
			flag=0x5a;
			iBytes=Mesg_send(iMesgID,&strupMesg_c,IPC_NOWAIT);
			if(iBytes==-1)
				printf("....svmsg_c: Send Message Error ....\n");			sleep(2);
		}
		iBytes=Mesg_recv(iMesgID,&strupMesg_s,IPC_NOWAIT);		if(iBytes<=0){
			printf("....svmsg_c: No Received Message ....\n");			sleep(3);
		}
		else{			printf("....svmsg_c: Received Message:%d ....\n",iBytes);			for(i=0;i<strupMesg_s.iMesgLen;i++)				printf("%x ",strupMesg_s.cMesgData[i]);			printf("\n");
			flag=0;
		}
	}

	Mesg_ctrl(iMesgID,IPC_RMID,NULL);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -