home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] Sockets - need concept only.

  • Subject: Re: [OCLUG-Tech] Sockets - need concept only.
  • From: Bart Trojanowski <bart [ at ] jukie [ dot ] net>
  • Date: Tue, 9 Aug 2005 13:15:06 -0400
IPC is restricted to a single host (on most operating systems anyways).

Sockets can be used for IPC, but they can also be used for communication
between programs on different hosts, so they are much more flexible.

Most of the time sockets are used for comunication between user space
applications.  For a few things the kernel can export it's APIs using
sockets.  Basically, they decided to use the already well known socket
interface instead of creating a new ioctl or system-call based API.

So, why do you want a socket?

You want a socket if you want two processes to communicate, where the
two processes are not (or may be not) on the same host.

Even on the same host, it's sometimes better to use sockets over shared
memory.  For example if you are passing a stream of data between two
processes; that could be a real pain to manage manually.  

More importantly, it's easy to port a UNIX-domain-socket application to
start using TCP sockets, then it is to port a shared-memory one to use
TCP socktes.  ... again, you would want to use TCP socktes if one of the
applications migrated to a foreign host.

-Bart

* William Case <billlinux [ at ] rogers [ dot ] com> [050809 12:55]:
> Hi;
> 
> I am 2/3 the way through Richard Stevens "UNIX Network Programming"
> and I seemed to have missed something about sockets.  A really quick
> short explanation would be helpful.  The question I have is:
> 
> "Why do I need a socket in the first place?"
> 
> A socket is used for interprocess communications, is it not?  If I were
> to sit down to write a communications program, why would I say to myself
> "OK, one of the first things I need is to create a socket"?  Why not
> shared memory, a buffer, an open user space file to write to and read
> from?
> 
> Really, most of what I have read in Steven's text, in the man pages or
> google I can follow, but nothing I've read answers what to me is the
> first question "Why would I do it?"  The literature I have read tells me
> how to create and use a socket, but nothing states bluntly why.
> 
> I'm guessing, but are sockets the only way to communicate between
> modules in the kernel and stuff in user space (processes, data,
> programs)?  And if so, is that accomplished with the system calls?
> 
> Regards Bill
> 
> 
> 
> 
> 
> _______________________________________________
> Linux mailing list
> Linux [ at ] lists [ dot ] oclug [ dot ] on [ dot ] ca
> http://www.oclug.on.ca/mailman/listinfo/linux

-- 
				WebSig: http://www.jukie.net/~bart/sig/

Attachment: signature.asc
Description: Digital signature