Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 21st, 2007, 9:04 PM   #1
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 345
Rep Power: 4 cwl157 is on a distinguished road
named pipes question

I want to be able to open 2 way communications between people using named pipes (they are created using the mkfifo command). I am able to get one way communications to work by entering
cat > mypipe
on the one user login and
cat < mypipe
on the other user login. However, this is only 1 way communication. I also need it to go the other way too. I have tried to make another pipe and then do the same thing but reverse so it would read and write from and to the other screen but it seems like only one pipe is run at a time. Is there a way for one of the pipes to run in the background or something so i can have 2 way communication at the same time? Thanks. By the way i am using BASH and both users are logged into the same machine from remote locations.

Last edited by cwl157; Feb 21st, 2007 at 9:35 PM.
cwl157 is offline   Reply With Quote
Old Feb 21st, 2007, 10:40 PM   #2
a thing
Unverified User
 
a thing's Avatar
 
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0 a thing is on a distinguished road
The name FIFO implies that this can't be done.

Perhaps Plan 9 can do what you want. :beard:

Is this the entire purpose of the program or just a part of it? If it's just a part, do tell what the whole program will do. If that's the whole program, why not just use IRC or talk?
__________________
Warning: My posts may change (dramatically) within the first 15 minutes they're posted.
Got 'Nux?—GNU/Linux and other free software support.
It's GNU/Linux, not just Linux.

Last edited by a thing; Feb 21st, 2007 at 11:04 PM.
a thing is offline   Reply With Quote
Old Feb 21st, 2007, 11:07 PM   #3
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 345
Rep Power: 4 cwl157 is on a distinguished road
well the purpose of the program is to make a chat program between 2 users logged onto the same machine. However, each user can talk to more than one person but no conference calls so only 2 way communication. It starts by recognizing the word send and then a user name is entered after that and then a named pipe connection is made and a message is sent and then the receiving user receives the message and can send back. And the user can be talking to multiple users at the same time. However, as you said the more i think about it the more i do not think this is possible since when a pipe is set up to send and receive it is always waiting to send or always waiting to receive so how do you receive on the end thats waiting to send without breaking out of the pipe and entering a new one to receive? The only way i can see how to do it is to type send and the user name every time you want to send something because then after the send it would break out so you have the option to recieve. However, i was told this is unacceptable. Aside from the 2 way communication a log has to be made of the conversation and emailed to both parties after the conversation is over. And the use of talk is not acceptable either. I know i don't think this is a very thought out program either. Anyone have any ideas?
cwl157 is offline   Reply With Quote
Old Feb 22nd, 2007, 12:46 AM   #4
a thing
Unverified User
 
a thing's Avatar
 
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0 a thing is on a distinguished road
I still think using an existing solution like IRC, Jabber, talk, or even email would be best.

But just because this is fun, perhaps each end could have its own FIFO. But I'm not so sure about this after a little experimentation.
__________________
Warning: My posts may change (dramatically) within the first 15 minutes they're posted.
Got 'Nux?—GNU/Linux and other free software support.
It's GNU/Linux, not just Linux.
a thing is offline   Reply With Quote
Old Feb 22nd, 2007, 10:21 AM   #5
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 345
Rep Power: 4 cwl157 is on a distinguished road
yea i tried to use 2 pipes and couldn't get it to work.
cwl157 is offline   Reply With Quote
Old Feb 22nd, 2007, 4:10 PM   #6
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
ksh (the shell ) supports exactly what you want - it's called co-processes.
talk also does what you want. Both work from the command line.

Both of these are part of any POSIX1b (IEEE 1003.1 2004) implementation - including Linux.
jim mcnamara is offline   Reply With Quote
Old Feb 22nd, 2007, 4:36 PM   #7
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 345
Rep Power: 4 cwl157 is on a distinguished road
i have to use bash shell. and i have kind of a start but i still do not know how to get 2 way communication.
cwl157 is offline   Reply With Quote
Old Feb 22nd, 2007, 5:42 PM   #8
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 345
Rep Power: 4 cwl157 is on a distinguished road
By start i mean i have figured out how to check the command line arguments and make sure a user name is entered but the communication thing im still lost. like isn't there a way for one of the pipes to run in the background or something so when you type it will still send it and then have recieve running the foreground or something? I was told the & can be used to do this but haven't been able to get anything to work.
cwl157 is offline   Reply With Quote
Old Feb 23rd, 2007, 3:04 AM   #9
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 345
Rep Power: 4 cwl157 is on a distinguished road
alright i've made a lot of progress. i figured out how to get 2 way communication by having receive run in the background however, with the way send and receive are set up its like the second one created receives from its same pipe that it sends to it just prints on the screen twice instead of printing on the screen thats supposed to be receiving. One way communication works fine and 2 way would work if i could figure out how to get it to go to a different pipe or something. I thought to keep the multiple conversations and pipes straight i would just name the pipe after the user that's being sent the message however when the recipient sends a message back it uses the same pipe and therefore just prints out twice on the same screen instead of once on the other screen. I guess its like going in a circle or something? Any ideas on how to make it send to the other pipe? Also, this all only works if the same user is logged in at 2 different places. Any ideas on how to make it work with one user sending it to another because i couldn't get any kind of communication to work user to user. Heres what i have:
send.sh the send program
#!/usr/bin/bash

if [ "$1" = "" ]
then
  w | cut -f1 -d ' ';
  echo "Please enter a user name";
  read uname;
  #uname="$1";
  echo $uname;
else
  uname="$1";
  #echo $1;
  echo $uname;
fi
echo $uname;
mkfifo $uname
#mkfifo mypipe5
cat > $uname

receive.sh the receive program
#!/usr/bin/bash

pipeName=$(echo $(whoami));
#echo "pipename after assignment is"
#pipeName="mypipe5"
echo $pipeName
echo $pipeName;
mkfifo $pipeName;
cat < $pipeName&
So basically a circle is being created if send.sh is run after receive.sh is run because since the user names are both the same the pipes are both the same also. Is there a way to append like a 1 or something at the end of one of them so the names are different? However, wouldn't this make it impossible to receive for one user because the pipe that is being wrote to and read from would be different?
cwl157 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual pet site MySQL question proudnerd PHP 6 May 13th, 2006 8:22 PM
Attitudes Oddball Coder's Corner Lounge 29 Mar 18th, 2006 10:34 PM
How to post a question nnxion C++ 10 Jun 3rd, 2005 12:53 PM
How to post a question nnxion C++ 0 Jun 3rd, 2005 9:55 AM
How to post a question nnxion C 0 Jun 3rd, 2005 9:55 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC