![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
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 cat < mypipe Last edited by cwl157; Feb 21st, 2007 at 8:35 PM. |
|
|
|
|
|
#2 |
|
Unverified User
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0
![]() |
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 10:04 PM. |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
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?
|
|
|
|
|
|
#4 |
|
Unverified User
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
yea i tried to use 2 pipes and couldn't get it to work.
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#8 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
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& |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Virtual pet site MySQL question | proudnerd | PHP | 6 | May 13th, 2006 7:22 PM |
| Attitudes | Oddball | Coder's Corner Lounge | 29 | Mar 18th, 2006 9:34 PM |
| How to post a question | nnxion | C++ | 10 | Jun 3rd, 2005 11:53 AM |
| How to post a question | nnxion | C++ | 0 | Jun 3rd, 2005 8:55 AM |
| How to post a question | nnxion | C | 0 | Jun 3rd, 2005 8:55 AM |