Learning Python Networking(Second Edition)
上QQ阅读APP看书,第一时间看更新

Socket module in Python

To create a socket, the socket.socket() constructor is used, which can take the family, type, and protocol as optional parameters. By default, the AF_INET family and the SOCK_STREAM type are used.

The general syntax is socket.socket(socket_family, socket_type, protocol=0), where the parameters are as follows:

  • socket_family: This is either AF_UNIX or AF_INET
  • socket_type: This is either SOCK_STREAM or SOCK_DGRAM
  • protocol: This is usually left out, defaulting to 0