LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-02-2009, 11:28 PM   #1
whho
Member
 
Registered: Feb 2009
Posts: 38

Rep: Reputation: 16
Client Server using named pipes


Hey,

I am experimenting a client server model using 2 name pipes. I want the client to accept input from terminal and then send to the server, and also accept response from server and then send to the screen. The server is basically "bash -i".

I am trying this:

server$ mknod pipe1 p; mknod pipe2 p
server$ bash -i <pipe1 >pipe2 2>&1

client$ (in another terminal)
while true; do
read a
echo $a > pipe1
cat pipe2
done;



The problem is that I can just do the command once and then the server exit by itself. I wonder if there is any ctrl-d character wrongly sent to the server and hence closing it.

Would somebody please help? Thanks!
 
Old 02-03-2009, 07:27 PM   #2
Le Hibou
LQ Newbie
 
Registered: Jun 2007
Location: La Hulpe, Belgium
Distribution: Ubuntu 8.10 Intrepid
Posts: 6

Rep: Reputation: 1
echo $a > anyfile would delete anyfile first (or maybe just empty it?) but I don't know what effect it would have on a named pipe. However, I would try echo $a >> pipe1 and see if this makes a difference.
 
Old 02-03-2009, 08:52 PM   #3
whho
Member
 
Registered: Feb 2009
Posts: 38

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Le Hibou View Post
echo $a > anyfile would delete anyfile first (or maybe just empty it?) but I don't know what effect it would have on a named pipe. However, I would try echo $a >> pipe1 and see if this makes a difference.
Thank you very much for your suggestion. I just tried ">>" and also trying changing the shell script to use "#!/bin/bash" instead of "#!/bin/sh", but it didn't seem to make a difference.

 
Old 02-03-2009, 09:25 PM   #4
whho
Member
 
Registered: Feb 2009
Posts: 38

Original Poster
Rep: Reputation: 16
Hey,

Now I am guessing the problem was this: if I use
echo $a > pipe1
cat pipe2

The named pipe will be closed once the command is completed, and hence close the server as well (because the server [bash -i] relies on these named pipes to be the input and output.

Therefore, I am trying this now:


#!/bin/sh
exec 5>pipe1
exec 6<pipe2
while true; do
read a
echo $a >&5
cat <&6
done;

I am trying to keep the named pipes open by using "exec 5>pipe1" and "exec 6<pipe2", but this time I got a deadlock in the line "cat <&6" after receiving some output from the server.

It seems that keeping the pipes open is not a good idea.

Actually, I tried using 2 terminals, with one running "cat pipe2" and one running "cat >pipe1" and I succeeded. However, what I actually want to do is to have a client remotely controlling the server as if working on the server.

Any idea?
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Named pipes and C jobless Programming 2 10-21-2008 01:31 PM
named pipes not working over nfs the_ultimate_samurai Linux - Networking 2 09-02-2008 12:22 PM
named pipes lamtab Programming 12 12-11-2007 10:44 AM
Write command in named pipes sahel Programming 7 12-28-2005 06:05 AM
Use of Named Pipes casey0999 Linux - Software 3 08-03-2003 01:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:35 PM.

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