LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-08-2011, 09:06 PM   #1
ouou
LQ Newbie
 
Registered: May 2011
Posts: 2

Rep: Reputation: Disabled
Please help a problem in client-server ipc message 2 pipes communication


I want to have a message send & receive through 2 half-duplex pipes

Flow of data

top- half pipe:
stdin--->parent(client) fd1[1]--->pipe1-->child(server) fd1[0]

bottome-half pipe:
child(server) fd2[1]---->pipe2--->parent(client) fd2[0]--->stdout

I need to have boundary structed message mesg_len+mesg_type+mesg_data

The function is that if user input "Knock Knock" on stdin, which directs to client, client send this message to server on the top half pipe, server compares the string, if matches with "Knock Knock", then server reply message "Who's there?" to client throught the bottom half pipe, and client write this message to the stdout.

Below is my code:


int main(int argc, char ** argv){

int pipe1[2],pipe2[2];
pid_t childpid;
pipe(pipe1); //create 2 pipes
pipe(pipe2);

if ((childpid=fork())==0) { //child
close(pipe1[1]);
close(pipe2[0]);
server(pipe1[0],pipe2[1]);
exit(0);
}
//parent
close(pipe1[0]);
close(pipe2[1]);
client(pipe1[1],pipe2[0]);
waitpid (childpid,NULL,0);
return EXIT_SUCCESS;
}

Last edited by ouou; 06-11-2011 at 01:24 PM.
 
Old 06-09-2011, 03:26 PM   #2
Heraton
Member
 
Registered: Apr 2011
Location: Germany
Distribution: Mint 10, openSuSE
Posts: 58

Rep: Reputation: 3
Arrow some good advice...

Hello!

Although i am still pretty new here, i think there are quite some things you could do to help your case:

1st: People around here like the Code-Tag very much as it helps to read and understand your code. It may be added as described in Formatting...

2nd: Even without special options i got two warnings using gcc to compile your code. You might want to take a look at this, because some people might come to the conclusion you have a devil-may-care attitude. If you should have no idea what this warnings are about, don't hesitate to tell us. This way someone may be able to explain.

3dr: You should compile with -Wall option enabled, maybe even with -Wextra. I had to learn the hard way lately that warnings in c are best taken very seriously. In this case, at least one of the warnings in fact is an error, although this is most likely not what is wrong with your program.

I propose you take a look at this. Maybe i take another look at your program tomorrow, but right now i am too tired to do proper debugging...

regards, Heraton
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Prob: Client/Server Communication zak100 Programming 2 10-18-2010 12:14 PM
Server/Client communication using VM( specifically VirtualBox) Rawan Alhindawi Linux - Newbie 1 12-04-2009 07:22 AM
Client Server using named pipes whho Linux - General 3 02-03-2009 09:25 PM
Server Client communication Kakarot_Rathish Programming 7 01-09-2009 05:40 PM
Shared Memory vs. Pipes for IPC ta0kira Programming 11 12-23-2007 03:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration