📄 client1.c
字号:
/* client1 */#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>#include <string.h>#include <unistd.h>#include <signal.h>#define KEY_MSG 0x101#define MSGSIZE 128int main(){ int msgid; struct msgbuf { long mtype; int subtype; char mtext[MSGSIZE]; }bufin, bufout; msgid = msgget( KEY_MSG, 0666 ); /* open message queue created by server */ if( fork() == 0 ) { printf( "send message to client2 :" ); while(1) { fgets( bufout.mtext, MSGSIZE, stdin ); bufout.mtype = 1L; bufout.subtype = 2; msgsnd( msgid, &bufout, MSGSIZE+4, 0 ); } } else { while(1) { msgrcv( msgid, &bufin, MSGSIZE+4, 2L, 0 ); if( bufin.mtext[0] == 'x' || bufin.mtext[0] == 'X' ) { kill( fork(), SIGINT ); break; } printf("receive message from client2 :%s", bufin.mtext ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -