简体   繁体   中英

Unix and the python socket module?

I've just come across sockets and the python socket module (and am quite new to python!). What are AF_UNIX and SOCK_STREAM variables (?) used for? I've found them in a bit of code (in a method of a class):

self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

What is this assignment doing?

AF_UNIX is configuring the socket as a unix socket . A unix socket is a mechanism for two processes on the same system to communicate with each other. If it were set to AF_INET it would be a TCP/IP socket.

SOCK_STREAM is configuring how processes should talk over the socket, in this case the processes exchange a byte stream. See here .

You should also check out the python socket docs , as they're pretty good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM