Lab Exercise • Make chatting program using Message Queue • You must run 2 programs(users). • When each program starts, g

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Lab Exercise • Make chatting program using Message Queue • You must run 2 programs(users). • When each program starts, g

Post by answerhappygod »

Lab Exercise Make Chatting Program Using Message Queue You Must Run 2 Programs Users When Each Program Starts G 1
Lab Exercise Make Chatting Program Using Message Queue You Must Run 2 Programs Users When Each Program Starts G 1 (55.34 KiB) Viewed 26 times
Lab Exercise Make Chatting Program Using Message Queue You Must Run 2 Programs Users When Each Program Starts G 2
Lab Exercise Make Chatting Program Using Message Queue You Must Run 2 Programs Users When Each Program Starts G 2 (61.57 KiB) Viewed 26 times
Lab Exercise Make Chatting Program Using Message Queue You Must Run 2 Programs Users When Each Program Starts G 3
Lab Exercise Make Chatting Program Using Message Queue You Must Run 2 Programs Users When Each Program Starts G 3 (38.3 KiB) Viewed 26 times
#include <sys/msg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <errno.h>
struct msgbuf{
long msgtype;
char text[256];
};
int main(){
int send_id_int, recv_id_int;
char *send_id = NULL;
char *recv_id = NULL;
size_t size;
printf("My id:");
getline(&send_id, &size, stdin);
send_id[size-1] ='\0';
printf("Receiver's id:");
getline(&recv_id, &size, stdin);
recv_id[size-1] ='\0';
key_t send_k = ftok(".", atoi(send_id));
key_t recv_k = ftok(".", atoi(recv_id));
int send_qid = msgget(send_k, IPC_CREAT | 0660);
int recv_qid = msgget(recv_k, IPC_CREAT | 0660);
if(send_qid == -1 || recv_qid == -1){
perror("msgget error");
exit(0);
}
if(fork () == 0){
// Child - Receiver
}else{
// Parent - Sender
}
}
I need this C programming assignment. in C language. only modifying above source code
Lab Exercise • Make chatting program using Message Queue • You must run 2 programs(users). • When each program starts, get sender's id and receiver's id from stdin - Parent → sender, child → receiver • Sender: - Gets the message from stdin and sends the message to the receiver's id Receiver: - Receives message from other sender - Print out the message
Lab Exercise (cont.) • There should be no wait between sending normal message and receiving ack message (at sender) - add IPC_NOWAIT flags to the msgrev function - Check it "man msgrcy" Quit the program if the user inputs "quit" - When quitting, print out "QUIT" to stdout • Output Format · When receiver receives message from other sender: RECEIVED: $USER_MSG
1 Example input/output shjeongeswin:-/spp/week105 ./9.out My id:10 Receiver's id:20 hi 28! I'm 18. RECEIVED: Hi 18, nice to meet you I think this week assignment is so easy RECEIVED: I think so too! RECEIVED: Oh i finish my assignment! good bye- see you, don't forget say goodbye to TA- quit QUIT shjeongêswin:-/spp/weekjes ./a.out My id:20 Receiver's id:10 RECEIVED: hi 201 I'- 10. Hi 10, nice to meet you RECEIVED: I think this week assignment is so easy I think so too! Oh i finish my assignment! good bye- RECEIVED: see you, don't forget say goodbye to TA- quit QUIT
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply