LinuxQuestions.org
Review your favorite Linux distribution.
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 12-26-2005, 02:23 PM   #1
sahel
LQ Newbie
 
Registered: Dec 2005
Posts: 21

Rep: Reputation: 15
Question Write command in named pipes


Hi
I have a problem.
i am writing this program. It works between Client and The server. The Server Listens to a namedpipe .whenever a client comes up and wants to login , The client is asked for it's userid. This user id has to be written in the named pipe(that has already been opened) and be sent to the server. The server is going to creat another exclusive named pipe with this information for this user.
My question is that i don't know how to write userid in named pipe and how to create exclusive named pipe for this user according to this userid.
Thanks so much
 
Old 12-26-2005, 02:48 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86; Gentoo PPC; Gentoo Sparc64; FreeBSD; OS X; Solaris
Posts: 3,731
Blog Entries: 4

Rep: Reputation: 66
First of all. what language are you developing in?

Second, do you not intend to use this over the network? If so you may want to redesign using sockets now, as it will be more difficult to do it later if you need your app networked.

Third, to send data to a pipe you simply open it as a file object and write to it. Here's a trivial example using bash and python:
Code:
...from shell 1
# mkfifo pipe
# cat pipe

...from shell 2
# python
>>> p = open("./pipe","w")
>>> p.write("hello pipe\n")
>>> p.flush()
After this you will see "hello pipe" in your first shell.
 
Old 12-26-2005, 03:18 PM   #3
sahel
LQ Newbie
 
Registered: Dec 2005
Posts: 21

Original Poster
Rep: Reputation: 15
Hi
first of all thank you.
I am using C .

Last edited by sahel; 12-26-2005 at 06:36 PM.
 
Old 12-26-2005, 03:31 PM   #4
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86; Gentoo PPC; Gentoo Sparc64; FreeBSD; OS X; Solaris
Posts: 3,731
Blog Entries: 4

Rep: Reputation: 66
Quote:
printf("login name?")
scanf("%s",str);
wirte ("./server",str,strlen(str));
Sure. It's just a regular file object. You can operate on it as you can any other normal file. The only difference is that both ends must be open for data to pass, ie server must be open for reading and client must be open for writing.

Quote:
mk=mkfifo("here i want to use the username as the filename.how?) , 0777)
Well, you are getting the name of the user in your read call right? So just assign it to a variable and pass that to your mkfifo call. Depending on your code, you may have to clean it up a bit. I would imagine at the very least you will need to 'chomp' the newline character.

Last edited by bulliver; 12-26-2005 at 03:35 PM.
 
Old 12-26-2005, 03:43 PM   #5
sahel
LQ Newbie
 
Registered: Dec 2005
Posts: 21

Original Poster
Rep: Reputation: 15
Thank you for the responce

Last edited by sahel; 12-26-2005 at 06:38 PM.
 
Old 12-28-2005, 05:32 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,283

Rep: Reputation: 172Reputation: 172
You send data over the pipe. You decide what it means.
If it's a user id then it's a user id.

you can call your named pipe whatever you want.
(lay off /dev/tty /dev/sound /boot/vmlinuz tho)

I agree though, may just as well use sockets, not much more work but
more flexible approach. fifo's are ok for shell scripts.
 
Old 12-28-2005, 06:02 AM   #7
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by bulliver
Sure. It's just a regular file object. You can operate on it as you can any other normal file. The only difference is that both ends must be open for data to pass, ie server must be open for reading and client must be open for writing.
And: The reading process must actually read away any data coming in from the pipe, because buffers for pipes are fixed as well as small.
 
Old 12-28-2005, 06:05 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,283

Rep: Reputation: 172Reputation: 172
and don't forget to send a newline to flush the data through each time.
you'll sit there waiting for hours!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Disabling 'write command' hirenpandya Linux - Security 9 03-03-2009 05:10 PM
cannot find named.conf and /var/named kaushikma Red Hat 1 02-07-2004 12:49 PM
problem in write command mtest Programming 3 10-30-2003 06:30 AM
Virtual Host type, named or IP via SSL? Named VH is not possible? piratebiter Linux - Security 3 08-20-2003 05:27 PM
Use of Named Pipes casey0999 Linux - Software 3 08-03-2003 01:21 PM


All times are GMT -5. The time now is 06:17 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration