Unix domain socket

In client-server computing, a Unix domain socket is a Berkeley socket that allows data to be exchanged between two processes executing on the same Unix or Unix-like host computer.[1] This is similar to an Internet domain socket that allows data to be exchanged between two processes executing on different host computers.

Regardless of the range of communication (same host or different host),[2] Unix computer programs that perform socket communication are similar. The only range of communication difference is the method to convert a name to the address parameter needed to bind the socket's connection. For a Unix domain socket, the name is a /path/filename. For an Internet domain socket, the name is an IP address:Port number. In either case, the name is called an address.[3]

Two processes may communicate with each other if each obtains a socket. The server process binds its socket to an address, opens a listen channel, and then continuously loops. Inside the loop, the server process is put to sleep while waiting to accept a client connection.[4] Upon accepting a client connection, the server then executes a read system call that will block wait. The client connects to the server's socket via the server's address. The client process then writes a message for the server process to read. The application's algorithm may entail multiple read/write interactions. Upon completion of the algorithm, the client executes exit()[5] and the server executes close().[6]

For a Unix domain socket, the socket's address is a /path/filename identifier. The server will create /path/filename on the filesystem to act as a lock file semaphore. No I/O occurs on this file when the client and server send messages to each other.[7]

  1. ^ Kerrisk, Michael (2010). The Linux Programming Interface. No Starch Press. p. 1149. ISBN 978-1-59327-220-3. Sockets are a method of IPC that allow data to be exchanged between applications, either on the same host (computer) or on different hosts connected by a network.
  2. ^ Kerrisk, Michael (2010). The Linux Programming Interface. No Starch Press. p. 1150. ISBN 978-1-59327-220-3.
  3. ^ Kerrisk, Michael (2010). The Linux Programming Interface. No Starch Press. p. 1150. ISBN 978-1-59327-220-3. The server binds its socket to a well-known address (name) so that clients can locate it.
  4. ^ Stevens, Richard W.; Fenner, Bill; Rudoff, Andrew M. (2004). Unix Network Programming (3rd ed.). Pearson Education. p. 14. ISBN 81-297-0710-1. Normally, the server process is put to sleep in the call to accept, waiting for a client connection to arrive and be accepted.
  5. ^ Kerrisk, Michael (2010). The Linux Programming Interface. No Starch Press. p. 1169. ISBN 978-1-59327-220-3.
  6. ^ Kerrisk, Michael (2010). The Linux Programming Interface. No Starch Press. p. 1159. ISBN 978-1-59327-220-3.
  7. ^ Kerrisk, Michael (2010). The Linux Programming Interface. No Starch Press. p. 1166. ISBN 978-1-59327-220-3.