Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void client(int,int);
- void server(int,int);
- int main(){
- int Pipe_1[2],Pipe_2[2];
- pipe(Pipe_1);
- pipe(Pipe_2);
- if (fork()==0){
- close(Pipe_1[1]);
- close(Pipe_2[0)];
- server(Pipe_1[0], Pipe_2[1]);
- exit(0);
- }//if
- close(Pipe_1[0]);
- close(Pipe_2[1]);
- client(Pipe_2[0],Pipe_1[1]);
- wait(0);
- printf("\n");
- exit(0);
- }
- void client(int FdRead, int FdWrite){
- char Msg[80];
- int n;
- spintf(Msg,"To jest tekst");
- printf("\n CLIENT ---> send: %s", Msg);
- write(FdWrite,Msg,strlen(Msg));
- while((n=read(FdRead,Msg,80)) > 0)
- printf("\n Otrzymana wiadomosc od serwera: %s",Msg);
- return;
- }//client
- void server(int FdRead, int FdWrite){
- char Msg[80];
- int n;
- if ((n=read(FdRead,Msg,80))>0)
- printf("\n SERVER ---> receive: %s", Msg);
- else
- printf("\n Blad odczytu komunikatu";
- sprintf(Msg,"Hello I'm Pipe's Server and alive!!!");
- printf("\n SERVER send: %s",Msg);
- write(FdWrite,Msg,strlen(Msg));
- }//servers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement