消息队列的发送与接收.
2011-09-02 19:40
429 查看
//消息队列的发送操作
#include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/types.h> #include<sys/ipc.h> #include<sys/msg.h> #include<errno.h> #include<string.h> struct message { long msg_type; char txt[50]; }; int main(void) { key_t key; int qid; struct message msg; key = ftok(".",'a'); if((qid = msgget(key,IPC_CREAT|0600)) < 0) perror("msgget"); else printf("make msg success qid"); int n = 10; while(n--){ if((msgrcv(qid,&msg,sizeof(msg),200,0)) < 0) perror("msgrcv"); else printf("rcv message:%s\n",msg.txt); memset(msg.txt,0,sizeof(msg.txt)); } if(msgctl(qid,IPC_RMID,NULL) < 0) perror("msgctl"); else printf("delete msg success\n"); return(0); }
//消息队列的接收
#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<sys/types.h>#include<sys/ipc.h>#include<sys/msg.h>#include<errno.h>#include<string.h>struct message{long msg_type;char txt[50];};int main(void){key_t key ;int qid;struct message msg[10];key = ftok(".",'a');if((qid
= msgget(key,IPC_CREAT|0600)) < 0)perror("msgget");elseprintf("make msg success qid = %d\n",qid);int i = 10;while(i--){msg[i].msg_type = 200;strcpy(msg[i].txt," message....");if(msgsnd(qid,&msg[i],sizeof(struct message),0) < 0)perror("msgsnd");elseprintf("add
message success\n");}return 0;}
相关文章推荐
- Activemq 消息发送、接收java代码实现队列模式
- 练习代码,写个消息队列发送接收
- SpringBoot的RabbitMQ消息队列: 一、消息发送接收第一印象
- DotNetMQ-基于C#和.NET框架的开源消息队列系统 – 安装部署及消息发送接收范例
- java调用rabbitmq消息队列发送和接收消息实例
- 消息队列发送数据和接收数据
- 消息队列(一)——消息的简单发送与接收
- \t\tMSMQ 消息队列 安装MSMQ 创建发送接收队例消息
- 消息队列(一)——消息的简单发送与接收
- 消息队列实现接收发送的例子
- POSIX消息队列 发送接收简单子
- SpringBoot的RabbitMQ消息队列: 一、消息发送接收第一印象
- 关于Posix消息队列简单的发送接收消息的练习
- C#操作MSMQ向本地消息队列发送和接收消息
- IPC--消息队列 message queue(消息队列的创建,信息的发送和接收)
- 启动任务StartTask() 发送完消息队列 自己删除,接收方一直显示数据 用OSQFlush(Str_Q); //清空消息队列 下面纠结接收不到了 哈哈
- MSMQ 消息队列 安装MSMQ 创建发送接收队例消息
- PHP发送队列消息接收队列消息
- 使用JAVA向微软消息队列(MSMQ)发送和接收消息
- C语言消息队列-消息类型不同的发送和接收