After creating the socket, we need to connect to it using the connect method of the socket object. The socket is essentially an opening in the networking capacity of the computer. In connecting, we give it a host and port for network communication.
c.connect((host, port))It is worth noting that the address for the connection is given as a tuple (hence the double parentheses).
Before we can read from the socket, however, we need to make a file-like object from it. Remember, Python read and writes to file-like objects, not sockets. So, we essentially tell Python to view the socket as a file. All sockets have a function makefile that takes two arguments: the mode and the buffer size. In our case, we want a simple read mode that has no buffer.
fileobj = c.makefile('r', 0)
