Created
May 16, 2012 13:03
Message Queue - Server Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<mqueue.h> | |
#include<string.h> | |
#include<fcntl.h> | |
#include<sys/stat.h> | |
#define MESSAGE_PRIO 0 | |
int main(void) | |
{ | |
mqd_t MQDes; | |
int ret; | |
char Message[100]; | |
char MQName[10] = "/MQServer"; | |
int choice; | |
MQDes = mq_open(MQName, O_RDWR|O_CREAT|O_EXCL, 777, NULL); | |
if(MQDes == -1) | |
{ | |
perror("mq_open"); | |
return -1; | |
} | |
printf("Enter your inputs line by line.\nTo Exit, type 'OVER' .\n"); | |
do | |
{ | |
scanf("%s",Message); | |
ret = mq_send(MQDes, Message, sizeof(Message), MESSAGE_PRIO); | |
if(ret == -1) | |
{ | |
perror("mq_send"); | |
return -1; | |
} | |
}while(strcasecmp(Message, "OVER")); | |
printf("Do you want to exit the Queue. 1- Yes, 0 - No\n"); | |
scanf("%d", &choice); | |
if(choice == 1) | |
{ | |
ret = mq_close(MQDes); | |
if(ret == -1) | |
{ | |
perror("mq_close"); | |
return -1; | |
} | |
ret = mq_unlink(MQName); | |
if(ret == -1) | |
{ | |
perror("mq_unlink"); | |
return -1; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment