Prosty program klient - serwer [c]

0
//serwer.c
#include  <stdlib.h>
#include  <stdio.h>
#include  <sys/msg.h>

struct m_komunikat {
  long typ;
  int v;
};

int kom, kon = 1, pom2 = 1, t2;
char t;

int main(){
  struct m_komunikat msg;
  printf("Liczba ktora nalezy zgadnac to 134\n");
  
  if ((kom=msgget((key_t)1231, 0660 | IPC_CREAT))==-1) {
     perror("\n     S.msgget error\n");
     exit(-1);
  }   
  char answer;
  while(kon){
    if ((msgrcv(kom,&msg,sizeof(msg),0 ,0))==-1) {
      perror("\n    S.msgrcv error  ");
      kon=0;
    } else {
      switch(msg.typ) {
        case 1:
            kon=0;
            break;
        case 2:
	    t2 = msg.v;
              printf("Czy %d jest liczba ktorej szukasz?(T lub N)\n", t2);
	      scanf("%c", &answer);
	    break;
        default:
            break;
      }	    
     if(answer == 'T') break;
     else continue;
    }   
  }
  msgctl(kom, IPC_RMID, 0);
  printf("Dziekuje za uwage\n");
  return 0;
}
klient.c
#include  <stdlib.h>
#include  <stdio.h>
     
struct m_komunikat {
  long typ;
  int v;
};

int kom, kon, i;
int temp;

int main() {
  struct m_komunikat msg;
  if ((kom=msgget((key_t)1231, 0))==-1) {
    perror("\n     K.msgget error  ");
    exit(-1);
  }

  msg.typ = 2;
  scanf("%d", &temp);
  for (;;) {
      msg.v = temp;
      if ((msgsnd(kom, &msg, sizeof(msg),0)) == -1) {
         perror("\n    K.Awaria serwera  ");
         exit(-1);
      }   
      scanf("%d", &temp);
  }
  printf("\n\nKoniec pracy Klienta %d\n\n", msg.v);
  exit (0);
}

Użytkownik wymyśla sobie liczbe i czeka na prawidłową (zgadniętą) przez klienta liczbe. Mam problem, wprowadzam takie dane:
klient.c serwer.c
1 N
3 N
105 N
143 N
286 T

i w tym momencie serwer powinien zakończyć swoje działanie, jednak dopiero jak wpr. kilka kolejnych liczb do klienta, dopiero wtedy serwer konczy działanie, czy ktoś jest w stanie pomóc i poprawić błąd w moim programikach?

0

Zamieszczam bardziej uproszczona wersje:

serwer.c
#include  <stdlib.h>
#include  <stdio.h>
#include  <sys/msg.h>

struct m_komunikat1 { int v; };
int kom;

int main(){
  struct m_komunikat1 msg;
  
  kom=msgget((key_t)1231, 0666 | IPC_CREAT);

  char answer;
  for(;;){
    msgrcv(kom,&msg,sizeof(msg),0 ,0);
    printf("Czy %d jest liczba ktorej szukasz?(T lub N)\n", msg.v);
    scanf("%c", &answer);
    if(answer == 'T') break;  
  }
  msgctl(kom, IPC_RMID, 0);
  return 0;
}
klient.c
#include  <stdlib.h>
#include  <stdio.h>
#include  <sys/msg.h>
     
struct m_komunikat { int v; };
int kom, temp;

int main() {
  struct m_komunikat msg;

  if ((kom=msgget((key_t)1231, 0666 | IPC_CREAT))==-1) {
    perror("\n     K.msgget error  ");
    exit(-1);
  }
  for (;;) {
      scanf("%d", &msg.v);
      msgsnd(kom, &msg, sizeof(msg),0);
  }
  printf("\n\nKoniec pracy Klienta\n\n");
  exit (0);
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1