tags:

views:

148

answers:

5

Both can be used for communicating between different processes,

what's the difference?

A: 

(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."

VoodooChild
LOL,but it's not programing related..
wamp
@VoodooChild: Shame :)
Merlyn Morgan-Graham
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.
Greg Hewgill
@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 http://stackoverflow.com/questions/1235958/ipc-performance-named-pipe-vs-socket
VoodooChild
@VoodooChild , Is that true? I've always heard pipes can also be used for communications between two unrelated processes.
wamp
@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. http://msdn.microsoft.com/en-us/library/aa365150(VS.85).aspx
Jerry Coffin
@Jerry Coffin: you are correct in context to Named pipes in Windows. Now the same is not true if we are not talking windows!
VoodooChild
@wamp: check out the answer by "Roger Austin" in the following link "http://stackoverflow.com/questions/1746075/sockets-vs-named-pipes-for-local-ipc-on-windows" ....Although the question is for local IPC on windows it might answer some of your questions
VoodooChild
+2  A: 

(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.

Will A
Pipes also allow communication between different hosts. Note that it's tagged [Windows], so we're talking about Windows pipes, not Unix pipes here.
Jerry Coffin
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): http://msdn.microsoft.com/en-us/library/aa365588%28v=VS.85%29.aspx
wamp
@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
@Will A: 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.
Jerry Coffin
+1  A: 

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 )

bioffe
A: 

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).

Pickbothmanlol
+2  A: 

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.

Jerry Coffin