1

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;
alk
  • 69,737
  • 10
  • 105
  • 255
user3266496
  • 23
  • 1
  • 3
  • You might like to show us the definition and initialisation of `m`, `risp` as well as the definition of `messaggio`. – alk Feb 10 '14 at 09:43
  • typedef struct{ long type; int pid; scelta tipo; int aula; int giorno; bool finito; } messaggio; – user3266496 Feb 10 '14 at 09:55
  • 1
    "*the client received wrong number*" which member of `messaggio` are you refering to? Which value are you sending? How do you set it in the sender? How do you inspect, print, show, read it in the receiver? – alk Feb 10 '14 at 10:08
  • He received wrong number only in the memember aula and giorno. The others are ok. I make a logfile. I use semaphores, may this could be the problem? – user3266496 Feb 10 '14 at 10:13

0 Answers0