Whether to request information or to serve it, in order to access the Internet, we need to create a socket. The syntax for this call is as follows:
<variable> = socket.socket(<family>, <type>)
The recognised socket families are:
- AF_INET: IPv4 protocols (both TCP and UDP)
- AF_INET6: IPv6 protocols (both TCP and UDP)
- AF_UNIX: UNIX domain protocols
The socket type refers to the type of communication used through the socket. The five socket types are as follows:
- SOCK_STREAM: a connection-oriented, TCP byte stream
- SOCK_DGRAM: UDP transferral of datagrams (self-contained IP packets that do not rely on client-server confirmation)
- SOCK_RAW: a raw socket
- SOCK_RDM: for reliable datagrams
- SOCK_SEQPACKET: sequential transfer of records over a connection
So let's create a socket and assign it to a variable.
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
