/* Msg Sprejemnik */ #include #include #include #include #define MSG_TYPE 1 /* Sprejemam sporocila tega tipa */ struct MsgReceive_t{ long MsgType; long SenderId; char Message[128]; }; int main( argc, argv ) int argc; char **argv; { int MsgId, MsgReceiveSize, Sprejel; struct MsgReceive_t MsgReceive; if( (MsgId = msgget( ftok("msgkey", 'k'), IPC_CREAT | 0644 )) == -1 ){ printf("%s: Napaka, msgget ni uspel\n", argv[0]); exit( 1 ); } MsgReceiveSize = sizeof(MsgReceive) - sizeof( long ); for( ; ; ){ if((Sprejel=msgrcv( MsgId, &MsgReceive, MsgReceiveSize, MSG_TYPE, 0 )) == -1 ){ printf("%s: Napaka, msgrcv ni uspel\n", argv[0]); exit( 2 ); } MsgReceive.Message[Sprejel- sizeof(long)] = 0; printf("Tip sporocila: %4d \n", MsgReceive.MsgType ); printf("Id Oddajnika : %4d \n", MsgReceive.SenderId ); printf("Sporocilo: %s\n", MsgReceive.Message ); } msgctl( MsgId, IPC_RMID, 0 ); /* to se nikoli ne izvrsi */ exit( 0 ); }