request.c

来自「scounix编译通过,c/s完整实现」· C语言 代码 · 共 32 行

C
32
字号
/****./request.c*给服务器发送请求*/#include <errno.h>#include <sys/types.h>       #include  <sys/ipc.h>#include <sys/msg.h>#define MSGKEY 3756main(){	struct msgbuf{		int mtype ;		int mtext ;	}buf ;	int msqid , pid ;	msqid = msgget(MSGKEY, 0666|IPC_CREAT);	pid = getpid();	buf.mtext = pid ;	buf.mtype = 1 ;	/*向服务方发送请求,消息类型是1*/	msgsnd(msqid, &buf, sizeof(buf.mtext), 0);	/*从服务方接受应答消息*/	msgrcv(msqid, &buf, 256, pid, MSG_NOERROR);	printf("process %d receive a acknowledgment from server, type is :%d\n",pid, buf.mtype);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?