Error during the communication on a msg queue

132 Views Asked by At

I made a message queue, but when assistant send the message to his client, the client received wrong number: -1081388352. This is for every number I send. There is no error during the msgget and even durign msgcrv or msgsnd. The code for the send:

key_t chiave_ac = ftok("prenotazione.c", 'M');
    if(chiave_ac == -1){
        perror("ftock");
        exit(EXIT_FAILURE);
    }
    int coda_ac = msgget(chiave_ac, IPC_CREAT | 0642);
    if(coda_ac == -1){
        perror("msgget");
        exit(EXIT_FAILURE);
    }

if (msgsnd(coda_ac, &m, sizeof(messaggio)-sizeof(long), 0) == -1) {
            perror("msgsnd");
            exit(EXIT_FAILURE);
}

Recivied:

key_t chiave_ac = ftok("prenotazione.c", 'M');
    if(chiave_ac == -1){
        printf("Errore nel generare la chiaveAC \n");
        perror("ftok");
        exit(1);
    }
    int id_ac  = msgget(chiave_ac, 0);
    if (id_ac == -1){
        perror("msgget ac");
        exit(EXIT_FAILURE);
    }
if( msgrcv(id_ac, &risp, sizeof(messaggio)-sizeof(long), getpid(), 0) == -1){
                    printf("errore ricezione \n");
                    fflush(stdout);
}

What I'm doing wrong? There's an error in some flag?


[added from comment:]

typedef struct
{
  long type; 
  int pid; 
  scelta tipo; 
  int aula; 
  int giorno; 
  bool finito; 
} messaggio;
0

There are 0 best solutions below