The socket module
Types and functions needed to work with sockets can be found in Python in the socket module. The socket module exposes all of the necessary pieces to quickly write TCP and UDP clients and servers. The socket module has almost everything you need to build a socket server or client. In the case of Python, the socket returns an object to which the socket methods can be applied.
This module comes installed by default when you install the Python distribution.
To check it, we can do so from the Python interpreter:
In this screenshot, we see all the constants and methods that we have available in this module. The constants we see in the first instance within the structure that has returned the object. Among the most-used constants, we can highlight the following:
socket.AF_INET
socket.SOCK_STREAM
A typical call to build a socket that works at the TCP level is:
socket.socket(socket.AF_INET,socket.SOCK_STREAM)