11

Both can be used for communicating between different processes,

what's the difference?

0

5 Answers 5

6

Windows has two kinds of pipes: anonymous pipes and named pipes. Anonymous pipes correspond (fairly) closely to Unix pipes -- typical usage is for a parent process to set them up to be inherited by a child process, often connected to the standard input, output and/or error streams of the child. At one time, anonymous pipes were implemented completely differently from named pipes so they didn't (for one example) support overlapped I/O. Since then, that's changed so an anonymous pipe is basically just a named pipe with a name you don't know, so you can't open it by name, but it still has all the other features of a named pipe (such as the aforementioned overlapped I/O capability).

Windows named pipes are much more like sockets. They originated with OS/2, where they were originally the primary mechanism for creating client/server applications. They were originally built around NetBIOS (i.e., used NetBIOS both for addressing and transport). They're tightly integrated with things like Windows authentication, so you can (for example) have a named pipe server impersonate the client to restrict the server to doing things the client would be able to do if logged in directly. More recently, MS has gone to some trouble to get rid of the dependence on NetBIOS, but even though they can now use IP as their transport (and DNS for addressing, IIRC) they're still used primarily for Windows machines. The primary use on other machines is to imitate Windows, such as by running Samba.

5

(Shamelessly cribbed from http://www.perlmonks.org/?node_id=180842)

Pipes are fast and reliable, because they are implemented in memory on a single host where both communicating processes run. Sockets are slower and less reliable, but are much more flexible since they allow communication between processes on different hosts.

4
  • 3
    Pipes also allow communication between different hosts. Note that it's tagged [Windows], so we're talking about Windows pipes, not Unix pipes here. Commented Aug 19, 2010 at 4:20
  • Can one pipe be used multiple times? As in this article it seems to me that a pipe can only be used once(will be closed once used): msdn.microsoft.com/en-us/library/aa365588%28v=VS.85%29.aspx
    – wamp
    Commented Aug 19, 2010 at 4:21
  • @Jerry - true - once this happens (inter-machine communication) is there a great deal difference between a pipe and a socket, at least in terms of speed?
    – Will A
    Commented Aug 19, 2010 at 6:39
  • I haven't done a test recently enough to really know. I did test once (~1995) and pipes came out faster, but that doesn't mean much about more recent versions of Windows. Commented Aug 19, 2010 at 13:08
2

(Off the top of my head)

Pipe: A tube with a small bowl at one end; used for smoking tobacco

Socket: Receptacle where something (a pipe, probe or end of a bone) is inserted

Anyways:

"A major difference between pipes and sockets is that pipes require a common parent process to set up the communications channel. A connection between sockets can be set up by two unrelated processes, possibly residing on different machines."

6
  • 1
    This is the trouble with naming things, it's hard. In the Windows world, a "named pipe" is more like a socket and is used to connect clients to servers on different machines. Commented Aug 19, 2010 at 4:06
  • @Greg Hewgill: Good point however "Named pipes and sockets are not functionally equivalent; sockets provide more features (they are bidirectional, for a start)." according to stackoverflow.com/questions/1235958/… Commented Aug 19, 2010 at 4:10
  • @VoodooChild , Is that true? I've always heard pipes can also be used for communications between two unrelated processes.
    – wamp
    Commented Aug 19, 2010 at 4:11
  • @VoodooChild: While you can create a named pipe as inbound-only or outbound-only, you can also create it as duplex, if that's what you want. msdn.microsoft.com/en-us/library/aa365150(VS.85).aspx Commented Aug 19, 2010 at 4:24
  • @Jerry Coffin: you are correct in context to Named pipes in Windows. Now the same is not true if we are not talking windows! Commented Aug 19, 2010 at 4:30
1

Sockets would use some sort of IP protocol like TCP/IP or UDP, thus would be slower, but your code'd be more portable if you'd need to communicate over a network. There is a third Shared mem approach and forth Mach ports (in this case I am not sure about it would work with Windows )

-5

They both do the same function, the only difference is that pipes are more efficient as they are closest one can get to the barebones of internets. Sockets are an abstraction built on top of series of tubes (pipes) as a result they are slower (just as java is slower than native assembly code).

Not the answer you're looking for? Browse other questions tagged or ask your own question.