Advertisement
Guest User

Untitled

a guest
May 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <process.h>
  4. #include <sys/neutrino.h>
  5.  
  6. int main(int argc, char *argv[]) {
  7.     int chid = 0, connId, sendId;
  8.     pid_t pidServ = getpid();
  9.     char buffer[4092];
  10.     switch( fork() ){
  11.         case -1:
  12.             printf("Error -- fork()");
  13.             break;
  14.        
  15.         case 0: // CHILD
  16.             if( connId = ConnectAttach( 0, pidServ, chid, _NTO_SIDE_CHANNEL, 0) == -1)
  17.                 printf("Error -- ConnectionAttach!");
  18.             while(1){
  19.                 strcpy( buffer, "Komunikat do wyslania");
  20.                 sendId = MsgSend( connId, buffer, strlen( buffer), buffer, 4092 );
  21.             }
  22.             ConnectDetach( connId );
  23.         break;
  24.        
  25.         default: // PARENT
  26.             if( chid = ChannelCreate( _NTO_CHF_COID_DISCONNECT ) == -1)
  27.                 printf("Error -- ChannelCreate()");
  28.             while(1){
  29.                 int rcvId = MsgReceive( chid, buffer, 4092, 0 );
  30.                 strcpy(buffer, "Odebralem komunikat!");
  31.                 MsgReply( rcvId, 0, buffer, strlen(buffer) );
  32.             }
  33.             ChannelDestroy( chid );
  34.             break;
  35.     }
  36.     return EXIT_SUCCESS;
  37. }
  38. /*
  39. Program ma tworzyc 2 procesy komunikujace sie ze soba za pomoca mech.komunikatow
  40.  
  41. server - proces odbierajacy - tworzy kanal polaczeniowy
  42. klient - proces wysylajacy
  43.  
  44. role maja sie nie zmieniac
  45.  
  46. program ma tworzyc procesy potomne i to one maja sie komunikowac
  47.  
  48. Procesy potomne -> fork()
  49. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement