Overview:
-
The socket module function recv_fds() receives file descriptors sent from a Unix Domain Socket. To send file descriptors refer to send_fds().
-
The file descriptors are reconstructed by the Unix kernel for them to work as expected at the process where they are received.
Example - Client:
# Example Python program that requests for # Create a Unix Domain Socket # Bind the Unix Domain socket to a path # Send the file names for which the descriptors # Receive the file descriptors # File descriptor list # Read from each file descriptor |
Output:
(b'Sending the files you asked for->', [4, 5, 6], 0, None) b'Course1\nCourse2\n' b'Campus1\nCampus2' b'Contacts\n' |
Example - Server:
# Example Python program that sends back file # Create a Unix Domain Socket # Bind the Unix Domain Socket to a path # Move the socket to listen state # Accept connections from clients # Get the names of the files fdList = [] |
Output:
Server listening for file (descriptor) requests: ['./courses.txt', './campusinfo.txt', './contacts.txt'] ./courses.txt ./campusinfo.txt ./contacts.txt Server listening for file (descriptor) requests: |