Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <process.h>
- #include <sys/neutrino.h>
- int main(int argc, char *argv[]) {
- int chid = 0, connId, sendId;
- pid_t pidServ = getpid();
- char buffer[4092];
- switch( fork() ){
- case -1:
- printf("Error -- fork()");
- break;
- case 0: // CHILD
- if( connId = ConnectAttach( 0, pidServ, chid, _NTO_SIDE_CHANNEL, 0) == -1)
- printf("Error -- ConnectionAttach!");
- while(1){
- strcpy( buffer, "Komunikat do wyslania");
- sendId = MsgSend( connId, buffer, strlen( buffer), buffer, 4092 );
- }
- ConnectDetach( connId );
- break;
- default: // PARENT
- if( chid = ChannelCreate( _NTO_CHF_COID_DISCONNECT ) == -1)
- printf("Error -- ChannelCreate()");
- while(1){
- int rcvId = MsgReceive( chid, buffer, 4092, 0 );
- strcpy(buffer, "Odebralem komunikat!");
- MsgReply( rcvId, 0, buffer, strlen(buffer) );
- }
- ChannelDestroy( chid );
- break;
- }
- return EXIT_SUCCESS;
- }
- /*
- Program ma tworzyc 2 procesy komunikujace sie ze soba za pomoca mech.komunikatow
- server - proces odbierajacy - tworzy kanal polaczeniowy
- klient - proces wysylajacy
- role maja sie nie zmieniac
- program ma tworzyc procesy potomne i to one maja sie komunikowac
- Procesy potomne -> fork()
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement