tags:

views:

912

answers:

3

When using socket in the UNIX domain, it is advisable to use path name for the directory directory mounted on the local disk. The UNIX domain only allows interprocess communication for process working on same machine.

Can you please explain the above line? It is about a socket in the UNIX DOMAIN.

Thanks!

+9  A: 

A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint that is similar to an Internet socket, but does not use a network protocol for communication. It is used in POSIX operating systems for inter-process communication. The correct standard POSIX term is POSIX Local IPC Sockets.

Unix domain connections appear as byte streams, much like network connections, but all data remains within the local computer. UNIX domain sockets use the file system as address name space, i.e. they are referenced by processes as inodes in the file system. This allows two distinct processes to open the same socket in order to communicate. However, the actual communication (the data exchange) does not use the file system, but buffers in kernel memory.

In addition to sending data, processes can send file descriptors across a Unix domain socket connection using the sendmsg() and recvmsg() system calls.

thanks for reply,so unix domain socket is for interprocess communication between two process on the same system,just like any other ipc mechanism like sharedmemory.So using unix domain we cant make communication between two machine.
mawia
@mawia - that is correct. For instance, you can talk to the local X window server over a Unix Domain Socket by setting your DISPLAY environment variable to ":0.0" or over a TCP/IP socket by setting it to "localhost:0.0".
Paul Tomblin
Look up AF_INET for the IP sockets to communicate between different hosts.
Just one thing that doesn't sound right: "Unix domain connections appear as byte streams": Local sockets can be both byte streams (SOCK_STREAM) and datagrams (SOCK_DGRAM and SOCK_SEQPACKET).
Juliano
Also worth noting: AF_UNIX sockets are only available on *nix-based systems (Linux, OSX, etc.) They are not available on Windows - which is one reason that, for example, they are not available in Java as a method of ipc.
rascher
`AF_UNIX` already makes it sound quite UNIX-specific, no? On the other hand, the synonyms `AF_FILE` and `AF_LOCAL` might have enlightened OP more than the common `AF_UNIX` name...
ephemient
+2  A: 

The end-points of UNIX domain sockets are represented by files in the file system (instead of by host / port).

However the communication between processes is done within the local system and does not result in a seekable file getting stored anywhere.

The advantage of using the file system as the namespace for the end-points is that normal file permissions and ACLs can be applied - if you can't open the end-point you can't connect. IP sockets have no such mechanism.

Alnitak
/*ACLs can be applied - if you can't open the end-point you can't connect.*/plz explain the above lines of your's.
mawia
it means that (for example) if the UNIX filename is chmod 0700 only the owner of the file (or root) can open the socket. Thus there is an extra level of security applied before the socket may even be opened.
Alnitak
+1  A: 

It means that if you create a AF_UNIX socket on a NFS disk which is shared between two machines A and B, you cannot have a process on A writing data to the unix socket and a process on B reading data from that socket.

The communication happens at kernel level, and you can only transfer data among processes sitting in the same kernel.

Stefano Borini