带有 C 的消息队列传递 2 个数字和 1 个运算符,但在服务器文件中出错

问题描述

在消息队列中,我创建了 server.c 和 client.c。创建了一个包含 2 个数字的结构,1 个字符用于操作员,1 个字符用于消息类型。 程序即将向服务器发送两个数字和一个运算符,服务器执行该程序并将该表达式的答案发送回客户端。

但我不断收到以下错误

删除标识符

我不知道我哪里做错了。

header.h

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
        <version>2.3.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.9.1</version>
    </dependency>
</dependencies>

client.c

#include <stdio.h>
#include <stdlib.h>
#include <sys/msg.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/types.h>

`

server.c

#include "./header.h"
#define KEY 777
#define SIZE 50

struct message
{
    long type;
    double no1,no2;
    char operator;
    char ans[SIZE];
};

int main()
{
    struct message msg;

    int qid = msgget((key_t)KEY,IPC_CREAT | 0666);

    if (qid < 0)
        perror("Error creating queue");
    else
    {
        printf("Enter no1 : ");
        scanf("%lf",&msg.no1);
        printf("Enter no2 : ");
        scanf("%lf",&msg.no2);
        getc(stdin);
        printf("Enter operator : ");
        msg.operator= getchar();
        msg.type = 1;
        if (msgsnd(qid,&msg,sizeof(msg) - sizeof(msg.type),IPC_NowAIT) < 0)
            perror("Error to write data");
        else
        {
            // if (msgrcv(qid,sizeof(msg.ans),2,0) < 0)
            //     perror("error to read response");
            // else
            // {
            //     printf("%s\n",msg.ans);
            // }
        }
        msgctl(qid,IPC_RMID,NULL);
    }
    return 0;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)