Unix ___domain socket: Difference between revisions

Content deleted Content added
No edit summary
Tags: Reverted Mobile edit Mobile web edit
Line 1:
{{short description|Mechanism for data exchange between processes executing on the same host}}
In [[Client–server model|client-server computing]], a '''Unix ___domain socket''' is a [[Berkeley sockets|Berkeley socket]] that allows data to be exchanged between two [[Process (computing)|processes]] [[Execution (computing)|executing]] on the same [[Unix]] or [[Unix-like]] host computer.<ref name="lpi-p1149_quote">{{cite book
|title=The Linux Programming Interface
|last=Kerrisk
|first=Michael
|publisher=No Starch Press
|year=2010
|quote=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.
|isbn=978-1-59327-220-3
|page=1149}}</ref> 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),<ref name="lpi-p1150">{{cite book
|title=The Linux Programming Interface
|last=Kerrisk
|first=Michael
|publisher=No Starch Press
|year=2010
|isbn=978-1-59327-220-3
|page=1150}}</ref> Unix [[computer program]]s that perform ''socket'' [[Inter-process communication|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 <code>/[[Path (computing)|path]]/[[filename]]</code>. For an ''Internet ___domain socket'', the name is an <code>[[IP address]]:[[Port (computer networking)|Port number]]</code>. In either case, the name is called an ''address''.<ref name="lpi-p1150_quote">{{cite book
|title=The Linux Programming Interface
|last=Kerrisk
|first=Michael
|publisher=No Starch Press
|year=2010
|isbn=978-1-59327-220-3
|quote=The server binds its socket to a well-known address (name) so that clients can locate it.
|page=1150}}</ref>
 
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 [[While loop|loops]]. Inside the loop, the server process is put to sleep while waiting to ''accept'' a client connection.<ref name="unp-p14_quote">{{cite book
|title=Unix Network Programming
|last1=Stevens
|first1=Richard W.
|last2=Fenner
|first2=Bill
|last3=Rudoff
|first3=Andrew M.
|publisher=Pearson Education
|year=2004
|edition=3rd
|isbn=81-297-0710-1
|quote=Normally, the server process is put to sleep in the call to ''accept'', waiting for a client connection to arrive and be accepted.
|page=14}}</ref> Upon ''accepting'' a client connection, the server then executes a [[read (system call)|read]] [[system call]] that will [[Blocking (computing)|block wait]]. The client ''connects'' to the server's socket via the server's ''address''. The client process then [[write (system call)|writes]] a [[String (computer science)|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 <code>exit()</code><ref name="lpi-p1169">{{cite book
|title=The Linux Programming Interface
|last=Kerrisk
|first=Michael
|publisher=No Starch Press
|year=2010
|isbn=978-1-59327-220-3
|page=1169}}</ref> and the server executes <code>close()</code>.<ref name="lpi-p1159">{{cite book
|title=The Linux Programming Interface
|last=Kerrisk
|first=Michael
|publisher=No Starch Press
|year=2010
|isbn=978-1-59327-220-3
|page=1159}}</ref>
 
For a ''Unix ___domain socket'', the socket's address is a <code>/path/filename</code> identifier. The server will create <code>/path/filename</code> on the [[file system|filesystem]] to act as a [[File_locking#Lock_files|lock file]] [[Semaphore (programming)|semaphore]]. No I/O occurs on this file when the client and server send messages to each other.<ref name="lpi-p1166">{{cite book
|title=The Linux Programming Interface
|last=Kerrisk
|first=Michael
|publisher=No Starch Press
|year=2010
|isbn=978-1-59327-220-3
|page=1166}}</ref>
 
==History==