简体   繁体   English

Unix和python socket模块?

[英]Unix and the python socket module?

I've just come across sockets and the python socket module (and am quite new to python!). 我刚刚遇到了套接字和python套接字模块(对python来说是相当新的!)。 What are AF_UNIX and SOCK_STREAM variables (?) used for? AF_UNIXSOCK_STREAM变量(?)用于什么? 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 . AF_UNIX将套接字配置为unix套接字 A unix socket is a mechanism for two processes on the same system to communicate with each other. Unix套接字是一种用于同一系统上的两个进程相互通信的机制。 If it were set to AF_INET it would be a TCP/IP socket. 如果将其设置为AF_INET ,它将是一个TCP / IP套接字。

SOCK_STREAM is configuring how processes should talk over the socket, in this case the processes exchange a byte stream. SOCK_STREAM正在配置进程应如何通过套接字进行通信,在这种情况下,进程将交换字节流。 See here . 这里

You should also check out the python socket docs , as they're pretty good. 您还应该检查python套接字文档 ,因为它们相当不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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