Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <string.h>
- #include <signal.h>
- #define MAX 10
- #define SERWER 1
- int IDqueue;
- typedef struct message
- {
- long msg_one;
- long msg_two;
- char text[MAX];
- } Message;
- int main()
- {
- int size;
- int i, j, pid;
- Message msg;
- if ((IDqueue = msgget(10, IPC_CREAT | 0600)) == -1)
- {
- printf("Create message queue failed\n");
- exit(EXIT_FAILURE);
- }
- printf("ID of queue: %d\n",IDqueue);
- while (1)
- {
- printf("SERVER: Waiting on message...\n");
- msg.msg_one = SERWER;
- if (msgrcv(IDqueue, &msg, MAX+9, msg.msg_one, MSG_NOERROR) == -1)
- {
- perror("Recieve message failed\n");
- exit(EXIT_FAILURE);
- }
- printf("SERVER: Recieve - %s addressed to %ld\n", msg.text, msg.msg_one);
- size = strlen(msg.text);
- for ( i = 0; i < size; i++)
- {
- msg.text[i] = toupper(msg.text[i]);
- }
- msg.msg_one = msg.msg_two;
- printf("SERVER: Sending - %s ---> %ld\n", msg.text, msg.msg_one);
- if ((msgsnd(IDqueue, &msg, strlen(msg.text)+9, 0)) == -1)
- {
- printf("Message added failed\n");
- exit(EXIT_FAILURE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment