我正在处理一个问题,这意味着一个基本的运行服务器客户端(之前完成一个)。问题是我运行的服务器比我运行的客户端。我的味精阙创建我nboth客户端需要我的字符作为输入发送它,我得到确认打印,但我的服务器msgrcv没有响应。基本的Unix服务器客户端IPC(消息队列)问题
SC
#include
#include
#include
#include
#include
#include
#include "struc.h"
int main(){
int qt;
struct msg m;
qt = msgget(1271,IPC_CREAT|IPC_EXCL|0600);
if(qt < 0){ perror("Error MSGGET()\n");}
printf("msg queue created!\n");
if(msgrcv(qt,&m,sizeof(struct msg),0,0)<0){
perror("Msg recive error");
}
printf("msg recived!\n");
msgctl(qt,IPC_RMID,NULL);
return 0;
}
CC
#include
#include
#include
#include
#include
#include
#include "struc.h"
int main(){
int qt;
struct msg m;
qt = msgget(1271,0);
if(qt < 0){ perror("~~~ Error MSGGET()\n");}
printf("msg created!\n");
printf("Enter one char: !\n");
scanf("%c",&m.c);
msgsnd(qt, &m,sizeof(struct msg),0);
printf("msg sent!\n");
return 0;
}
struc.h
struct msg{
long mtype;
// matrix M;
char c;
};
(用户自己创建的3个文件,你的CNA测试。任何想法是值得欢迎的,也许我错过了什么)
+1
m.mtype的价值是什么?目前尚未定义。如果碰巧是0或负值,则msgsend将失败。 –
+0
谢谢。这是忘记初始化mtype的问题。 –
+0
是的,我发现在发布前8分钟发现错误。自从90年代中后期以来,还没有使用过ipc.h,因此在发布任何内容之前,我必须阅读手册页来清理我的知识。 –