What is socket.AF_INET and socket.SOCK_DGRAM? What do they do?
阿新 • • 發佈:2018-11-11
tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
What is socket.AF_INET and socket.SOCK_DGRAM? What do they do?
AF_INET, where AF represents address family, is used to specifiy the type of address family with which the socket can communicate. To be specific, it is used for Internet Protocol v4 addresses (IPV4) with the value set to be 2.
Other address family members include:
Name Purpose
AF_UNIX, AF_LOCAL Local communication
AF_INET IPv4 Internet protocols
AF_INET6 IPv6 Internet protocols
AF_IPX IPX - Novell protocols
AF_NETLINK Kernel user interface device
AF_X25 ITU-T X.25 / ISO-8208 protocol
AF_AX25 Amateur radio AX.25 protocol
AF_ATMPVC Access to raw ATM PVCs
AF_APPLETALK Appletalk
AF_PACKET Low level packet interface
As for socket.SOCK_DGRAM, where DGRAM stands for datagram, it is used to specify the type of connection to be created. In this case, it is a constant of value 2 representing UPD connection.